10#include <sys/timerfd.h>
12#include "dawn/io/dummy_notify.hxx"
16static size_t dummyNotifyInitvalWordsPerValue(
size_t tlen)
18 if (tlen ==
sizeof(uint64_t))
26int CIODummyNotify::configureDesc(
const CDescObject &desc)
29 size_t parsed_dim = 1;
30 bool parsed_dim_set =
false;
31 size_t parsed_init_len = 1;
35 for (i = 0; i < desc.
getSize(); i++)
51 case IO_DUMMY_NOTIFY_CFG_INITVAL:
54 size_t word_step = dummyNotifyInitvalWordsPerValue(
getDtypeSize());
59 DAWNERR(
"Dummy notify IO init value "
60 "dimension must be > 0\n");
64 if (word_count % word_step != 0)
66 DAWNERR(
"Dummy notify IO init value word count "
67 "%zu is invalid for element size %zu\n",
73 init_len = word_count / word_step;
74 cfgval = &item->
data[0];
75 parsed_init_len = init_len;
77 offset += 1 + word_count;
81 case IO_DUMMY_NOTIFY_CFG_INTERVAL:
83 const uint32_t *tmp = &item->
data[0];
90 case IO_DUMMY_NOTIFY_CFG_DIM:
92 uint32_t dim = item->
data[0];
96 DAWNERR(
"Dummy notify IO dimension must be > 0\n");
101 parsed_dim_set =
true;
106 case IO_DUMMY_NOTIFY_CFG_NOTIFY_ON_WRITE:
108 notifyOnWrite = item->
data[0] != 0;
115 DAWNERR(
"unsupported dummy_notify objectCfg "
127 DAWNERR(
"unsupported dummy_notify cfg 0x08%" PRIx32
"\n", item->
cfgid.
v);
133 if (!parsed_dim_set && cfgval !=
nullptr)
135 parsed_dim = parsed_init_len;
138 if (cfgval !=
nullptr && parsed_init_len < parsed_dim)
140 DAWNERR(
"Dummy notify IO init value dimension %zu is smaller than "
141 "data dimension %zu\n",
148 cfglen = parsed_init_len;
153int CIODummyNotify::setVal(
const void *v,
size_t d)
155 DAWNASSERT(dlen * tlen == d,
"invalid input");
156 DAWNASSERT(val !=
nullptr,
"buffer not initialized");
160 std::memcpy(val, v, d);
162#ifdef CONFIG_DAWN_IO_TIMESTAMP
174int CIODummyNotify::applyInitval()
179 if (cfgval ==
nullptr)
184 DAWNASSERT(val !=
nullptr,
"buffer not initialized");
186 word_step = dummyNotifyInitvalWordsPerValue(tlen);
188 for (i = 0; i < dlen; i++)
190 std::memcpy(
static_cast<uint8_t *
>(val) + (i * tlen), &cfgval[i * word_step], tlen);
196CIODummyNotify::~CIODummyNotify()
206 notifyOnWrite =
false;
207#ifdef CONFIG_DAWN_IO_NOTIFY
211 return configureDesc(
getDesc());
218 val =
new (std::nothrow) uint8_t[dlen * tlen]();
221 DAWNERR(
"new failed\n");
225 ret = applyInitval();
228 delete[]
static_cast<uint8_t *
>(val);
234 if (writeData ==
nullptr || !writeData->isAllocated())
238 delete[]
static_cast<uint8_t *
>(val);
243#ifdef CONFIG_DAWN_IO_NOTIFY
246 DAWNERR(
"dummy_notify requires interval > 0\n");
249 delete[]
static_cast<uint8_t *
>(val);
260 delete[]
static_cast<uint8_t *
>(val);
274 delete[]
static_cast<uint8_t *
>(val);
288 for (i = 0; i < len; i++)
292#ifdef CONFIG_DAWN_IO_TIMESTAMP
295 std::memcpy(data.
getDataPtr(i), val, dlen * tlen);
306 int ret = setVal(data.
getDataPtr(), dlen * tlen);
308#ifdef CONFIG_DAWN_IO_NOTIFY
309 if (ret == OK && notifyOnWrite && writeData !=
nullptr)
313# ifdef CONFIG_DAWN_IO_TIMESTAMP
316 writeData->
getTs(0) = ts;
320 std::memcpy(writeData->
getDataPtr(), val, dlen * tlen);
324 (void)notifyData(writeData);
331#ifdef CONFIG_DAWN_IO_NOTIFY
337int CIODummyNotify::notify()
339 struct itimerspec tms;
347 tms.it_value.tv_sec = 0;
348 tms.it_value.tv_nsec = 1;
349 tms.it_interval.tv_sec = 0;
350 tms.it_interval.tv_nsec = 0;
352 ret = timerfd_settime(timfd_fd(), 0, &tms, NULL);
355 DAWNERR(
"timerfd_settime notify failed\n");
364 return timfd_start();
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemAtOffset(size_t offset) const
Get configuration item at specified offset.
virtual int getFd() const
Get file descriptor for notifications.
uint64_t getTimestamp()
Get current timestamp.
bool isTimestamp() const
Check if I/O supports timestamp.
size_t cfgCmnOffset(const SObjectCfg::SObjectCfgItem *cfg)
Get offset of configuration item in descriptor.
@ IO_CLASS_ANY
Any I/O class.
@ IO_CLASS_DUMMY_NOTIFY
Timer-driven dummy IO.
int init()
One-time initialize object after bindings are resolved.
int deinit()
De-initialize object.
int configure()
Configure object from descriptor data.
int doStart()
Start implementation hook.
size_t getDataSize() const
Get data size in bytes.
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
int doStop()
Stop implementation hook.
size_t getDataDim() const
Get data vector dimension.
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
CDescObject & getDesc()
Get descriptor object for this object.
size_t getDtypeSize() const
Get size of this object's data type.
uint8_t getDtype() const
Get data type field.
Out-of-tree user-extension hooks for Dawn.
Base interface for I/O data buffers (static and dynamic).
virtual void * getDataPtr(size_t batch=0)=0
Get pointer to data only (skips timestamp if present).
virtual uint64_t & getTs(size_t batch=0)=0
Get timestamp reference for batch.
Single configuration item within object.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
Heap-allocated dynamic I/O data buffer.
void * getDataPtr(size_t batch=0)
Get pointer to data only (skips timestamp if present).
io_ts_t & getTs(size_t batch=0)
Get timestamp reference for batch.
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
uint32_t cls
Object class (bits 21-29, max 511).
uint32_t id
Configuration identifier (bits 0-4, max 31).
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.