1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

move "external" part of shmem to separate files

This commit is contained in:
Georg Reinke 2017-04-07 12:57:40 +02:00
parent 45f5d9697a
commit 3a7af08799
7 changed files with 69 additions and 52 deletions

View file

@ -9,6 +9,7 @@
#pragma once
#include <string.h>
#include <stdint.h>
/* Forward declarations */
@ -70,4 +71,4 @@ int kernel_get_hugepage_size();
/** Set SMP affinity of IRQ */
int kernel_irq_setaffinity(unsigned irq, uintmax_t new, uintmax_t *old);
/** @} */
/** @} */

View file

@ -5,22 +5,10 @@
#include "memory.h"
#include "pool.h"
#include "queue.h"
#include "queue_signalled.h"
#include "shmem.h"
#define DEFAULT_SHMEM_QUEUESIZE 512
union shmem_queue {
struct queue q;
struct queue_signalled qs;
};
/** The structure that actually resides in the shared memory. TODO better name?*/
struct shmem_shared {
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 shmem {
const char* name; /**< Name of the shm object. */
int sample_size; /**< Number of data entries for each sample. */
@ -46,11 +34,4 @@ int shmem_close(struct node *n);
int shmem_read(struct node *n, struct sample *smps[], unsigned cnt);
int shmem_write(struct node *n, struct sample *smps[], unsigned cnt);
/* The interface functions that the external program should use. TODO put this
* in another file? */
struct shmem_shared * shmem_int_open(const char* name, size_t len);
size_t shmem_total_size(int insize, int outsize, int sample_size);
#endif /* _SHMEM_H_ */

23
include/villas/shmem.h Normal file
View file

@ -0,0 +1,23 @@
#pragma once
/* The interface functions that the external program should use. */
#include "pool.h"
#include "queue.h"
#include "queue_signalled.h"
union shmem_queue {
struct queue q;
struct queue_signalled qs;
};
/** The structure that actually resides in the shared memory. TODO better name?*/
struct shmem_shared {
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 shmem_shared * shmem_int_open(const char* name, size_t len);
size_t shmem_total_size(int insize, int outsize, int sample_size);

View file

@ -9,7 +9,7 @@ LIB_SRCS = $(addprefix lib/nodes/, file.c cbuilder.c shmem.c) \
$(addprefix lib/, sample.c path.c node.c hook.c \
log.c utils.c super_node.c hist.c timing.c pool.c \
list.c queue.c queue_signalled.c memory.c advio.c web.c api.c \
plugin.c node_type.c stats.c mapping.c sample_io.c\
plugin.c node_type.c stats.c mapping.c sample_io.c shmem.c \
)
LIB_CFLAGS = $(CFLAGS) -fPIC

View file

@ -9,6 +9,7 @@
#include "log.h"
#include "nodes/shmem.h"
#include "plugin.h"
#include "shmem.h"
#include "utils.h"
int shmem_parse(struct node *n, config_setting_t *cfg) {
@ -152,33 +153,3 @@ static struct plugin p = {
};
REGISTER_PLUGIN(&p)
size_t shmem_total_size(int insize, int outsize, int sample_size)
{
// we have the constant const of the memtype header
return sizeof(struct memtype)
// and the shared struct itself
+ sizeof(struct shmem_shared)
// the size of the 2 queues and the queue for the pool
+ (insize + outsize) * (2*sizeof(struct queue_cell))
// the size of the pool
+ (insize + outsize) * kernel_get_cacheline_size() * CEIL(SAMPLE_LEN(sample_size), kernel_get_cacheline_size())
// a memblock for each allocation (1 shmem_shared, 3 queues, 1 pool)
+ 5 * sizeof(struct memblock)
// and some extra buffer for alignment
+ 1024;
}
struct shmem_shared* shmem_int_open(const char *name, size_t len)
{
int fd = shm_open(name, O_RDWR, 0);
if (fd < 0)
return NULL;
void *base = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (base == MAP_FAILED)
return NULL;
/* This relies on the behaviour of the node and the allocator; it assumes
* that memtype_managed is used and the shmem_shared is the first allocated object */
char *cptr = (char *) base + sizeof(struct memtype) + sizeof(struct memblock);
return (struct shmem_shared *) cptr;
}

39
lib/shmem.c Normal file
View file

@ -0,0 +1,39 @@
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include "kernel/kernel.h"
#include "memory.h"
#include "utils.h"
#include "sample.h"
#include "shmem.h"
size_t shmem_total_size(int insize, int outsize, int sample_size)
{
// we have the constant const of the memtype header
return sizeof(struct memtype)
// and the shared struct itself
+ sizeof(struct shmem_shared)
// the size of the 2 queues and the queue for the pool
+ (insize + outsize) * (2*sizeof(struct queue_cell))
// the size of the pool
+ (insize + outsize) * kernel_get_cacheline_size() * CEIL(SAMPLE_LEN(sample_size), kernel_get_cacheline_size())
// a memblock for each allocation (1 shmem_shared, 3 queues, 1 pool)
+ 5 * sizeof(struct memblock)
// and some extra buffer for alignment
+ 1024;
}
struct shmem_shared* shmem_int_open(const char *name, size_t len)
{
int fd = shm_open(name, O_RDWR, 0);
if (fd < 0)
return NULL;
void *base = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (base == MAP_FAILED)
return NULL;
/* This relies on the behaviour of the node and the allocator; it assumes
* that memtype_managed is used and the shmem_shared is the first allocated object */
char *cptr = (char *) base + sizeof(struct memtype) + sizeof(struct memblock);
return (struct shmem_shared *) cptr;
}

View file

@ -4,11 +4,13 @@
#include "config.h"
#include "log.h"
#include "node.h"
#include "nodes/shmem.h"
#include "pool.h"
#include "queue.h"
#include "sample.h"
#include "sample_io.h"
#include "shmem.h"
#include "super_node.h"
#include "utils.h"