diff --git a/include/villas/nodes/websocket.h b/include/villas/nodes/websocket.h index a19cb65f7..707cf2538 100644 --- a/include/villas/nodes/websocket.h +++ b/include/villas/nodes/websocket.h @@ -36,7 +36,7 @@ struct websocket { struct list destinations; /**< List of websocket servers connect to in client mode (struct websocket_destination). */ struct pool pool; - struct queue_signalled queue; /**< For samples which are received from WebSockets a */ + struct queue_signalled queue; /**< For samples which are received from WebSockets */ }; /* Internal datastructures */ diff --git a/include/villas/sample.h b/include/villas/sample.h index acae32eed..392abf3da 100644 --- a/include/villas/sample.h +++ b/include/villas/sample.h @@ -32,19 +32,19 @@ enum sample_data_format { }; struct sample { - int sequence; /**< The sequence number of this sample. */ - int length; /**< The number of values in sample::values which are valid. */ - int capacity; /**< The number of values in sample::values for which memory is reserved. */ + int sequence; /**< The sequence number of this sample. */ + int length; /**< The number of values in sample::values which are valid. */ + int capacity; /**< The number of values in sample::values for which memory is reserved. */ - atomic_int refcnt; /**< Reference counter. */ - off_t pool_off; /**< This sample is belong to this memory pool (relative pointer). */ - struct node *source; /**< The node from which this sample originates. */ + atomic_int refcnt; /**< Reference counter. */ + off_t pool_off; /**< This sample belongs to this memory pool (relative pointer). */ + struct node *source; /**< The node from which this sample originates. */ /** All timestamps are seconds / nano seconds after 1.1.1970 UTC */ struct { struct timespec origin; /**< The point in time when this data was sampled. */ struct timespec received; /**< The point in time when this data was received. */ - struct timespec sent; /**< The point in time this data was send for the last time. */ + struct timespec sent; /**< The point in time when this data was send for the last time. */ } ts; uint64_t format; /**< A long bitfield indicating the number representation of the first 64 values in sample::data[] */ @@ -70,8 +70,8 @@ int sample_get(struct sample *s); /** Decrease reference count and release memory if last reference was held. */ int sample_put(struct sample *s); -/** Set number representation for a single value of a sample. */ +/** Get number representation for a single value of a sample. */ int sample_get_data_format(struct sample *s, int idx); -/** Get number representation for a single value of a sample. */ +/** Set number representation for a single value of a sample. */ int sample_set_data_format(struct sample *s, int idx, enum sample_data_format fmt); diff --git a/include/villas/sample_io.h b/include/villas/sample_io.h index 12acc46d6..20e2d76ee 100644 --- a/include/villas/sample_io.h +++ b/include/villas/sample_io.h @@ -71,6 +71,3 @@ int sample_io_villas_scan(const char *line, struct sample *s, int *fl); int sample_io_villas_fprint(FILE *f, struct sample *s, int flags); int sample_io_villas_fscan(FILE *f, struct sample *s, int *flags); - -/* JSON format */ - diff --git a/include/villas/shmem.h b/include/villas/shmem.h index 7725cae4d..ce88a9fa8 100644 --- a/include/villas/shmem.h +++ b/include/villas/shmem.h @@ -11,6 +11,7 @@ #include "queue.h" #include "queue_signalled.h" +/** A signalled queue or a regular (polling) queue, depending on the polling setting. */ union shmem_queue { struct queue q; struct queue_signalled qs; @@ -18,27 +19,50 @@ union shmem_queue { /** The structure that actually resides in the shared memory. */ struct shmem_shared { - size_t len; /**< Total size of the shared memory region.*/ + size_t len; /**< Total size of the shared memory region.*/ - int polling; /**< Whether to use a pthread_cond_t to signal if new samples are written to incoming queue. */ + int polling; /**< Whether to use a pthread_cond_t to signal if new samples are written to incoming queue. */ - union shmem_queue in; /**< Queue for samples passed from external program to node.*/ - union shmem_queue out; /**< Queue for samples passed from node to external program.*/ + union shmem_queue in; /**< Queue for samples passed from external program to node.*/ + union shmem_queue out; /**< Queue for samples passed from node to external program.*/ - struct pool pool; /**< Pool for the samples in the queues. */ + struct pool pool; /**< Pool for the samples in the queues. */ - pthread_barrier_t start_bar; + pthread_barrier_t start_bar; /**< Barrier for synchronizing the start of both programs. */ pthread_barrierattr_t start_attr; - atomic_size_t node_stopped; - atomic_size_t ext_stopped; + atomic_size_t node_stopped; /**< Set to 1 by VILLASNode if it is stopped/killed. */ + atomic_size_t ext_stopped; /**< Set to 1 by the external program if it is stopped/killed. */ }; +/** Open the shared memory object and retrieve / initialize the shared data structures. + * @param[in] name Name of the POSIX shared memory object. + * @param[inout] base_ptr The base address of the shared memory region is written to this pointer. + * @retval A valid shmem_shared* on success, or NULL with errno indicating the error on failure. + */ struct shmem_shared * shmem_shared_open(const char* name, void **base_ptr); +/** Close and destroy the shared memory object and related structures. + * @param[shm] The shared memory structure. + * @param[base] The base address as returned by shmem_shared_open. + */ int shmem_shared_close(struct shmem_shared *shm, void *base); +/** Read samples from VILLASNode. + * @param[shm] The shared memory structure. + * @param[smps] An array where the pointers to the samples will be written. The samples + * must be freed with sample_put after use. + * @param[cnt] Number of samples to be read. + */ int shmem_shared_read(struct shmem_shared *shm, struct sample *smps[], unsigned cnt); +/** Write samples to VILLASNode. + * @param[shm] The shared memory structure. + * @param[smps] The samples to be written. Must be allocated from shm->pool. + * @param[cnt] Number of samples to write. + */ int shmem_shared_write(struct shmem_shared *shm, struct sample *smps[], unsigned cnt); +/** Returns the total size of the shared memory region with the given size of + * the input/output queues (in elements) and the given number of data elements + * per struct sample. */ size_t shmem_total_size(int insize, int outsize, int sample_size); diff --git a/src/test-shmem.c b/src/test-shmem.c index 8b8a0c496..3db0b1908 100644 --- a/src/test-shmem.c +++ b/src/test-shmem.c @@ -25,7 +25,8 @@ struct shmem_shared *shared; void usage() { printf("Usage: villas-test-shmem SHM_NAME VECTORIZE\n"); - printf(" SHMNAME name of the shared memory object\n"); + printf(" SHMNAME name of the shared memory object\n"); + printf(" VECTORIZE maximum number of samples to read/write at a time\n"); } void quit(int sig)