* [PATCH 1/2] Introduce get_ioengine for external engines
@ 2014-02-12 19:13 Daniel Gollub
2014-02-12 19:13 ` [PATCH 2/2] engines/null: allow build as external C++ ioengine Daniel Gollub
2014-02-13 4:12 ` [PATCH 1/2] Introduce get_ioengine for external engines Jens Axboe
0 siblings, 2 replies; 5+ messages in thread
From: Daniel Gollub @ 2014-02-12 19:13 UTC (permalink / raw)
To: fio; +Cc: Daniel Gollub
This makes life easier for plugins written in C++
since they do not need to deal with struct initilization issues
with the ioengine_ops symbol.
With g++ a non-static ioengine_ops in global scope like this:
struct ioengine_ops ioengine = {
.name = "null",
.version = FIO_IOOPS_VERSION,
.queue = fio_null_queue,
.commit = fio_null_commit,
};
Results in:
cpp_null2.cc: At global scope:
cpp_null2.cc:112:1: error: C99 designator ‘name’ outside aggregate initializer
cpp_null2.cc:112:1: sorry, unimplemented: non-trivial designated initializers not supported
cpp_null2.cc:112:1: sorry, unimplemented: non-trivial designated initializers not supported
cpp_null2.cc:112:1: sorry, unimplemented: non-trivial designated initializers not supported
cpp_null2.cc:112:1: sorry, unimplemented: non-trivial designated initializers not supported
$
Example get_iongine() symbol usage:
---8<---
extern "C" {
void get_ioengine(struct ioengine_ops **ioengine_ptr) {
struct ioengine_ops *ioengine;
*ioengine_ptr = (struct ioengine_ops *) malloc(sizeof(struct ioengine_ops));
ioengine = *ioengine_ptr;
strcpy(ioengine->name, "cpp_null");
ioengine->version = FIO_IOOPS_VERSION;
ioengine->queue = fio_null_queue;
ioengine->commit = fio_null_commit;
ioengine->getevents = fio_null_getevents;
ioengine->event = fio_null_event;
ioengine->init = fio_null_init;
ioengine->cleanup = fio_null_cleanup;
ioengine->open_file = fio_null_open;
ioengine->flags = FIO_DISKLESSIO;
}
}
--->8---
Signed-off-by: Daniel Gollub <d.gollub@telekom.de>
---
ioengines.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/ioengines.c b/ioengines.c
index d71e372..c080da3 100644
--- a/ioengines.c
+++ b/ioengines.c
@@ -90,6 +90,7 @@ static struct ioengine_ops *dlopen_ioengine(struct thread_data *td,
{
struct ioengine_ops *ops;
void *dlhandle;
+ typedef void (*get_ioengine_t)(struct ioengine_ops **);
dprint(FD_IO, "dload engine %s\n", engine_lib);
@@ -107,6 +108,19 @@ static struct ioengine_ops *dlopen_ioengine(struct thread_data *td,
ops = dlsym(dlhandle, engine_lib);
if (!ops)
ops = dlsym(dlhandle, "ioengine");
+
+ /*
+ * For some external engines (like C++ ones) it is not that trivial
+ * to provide a non-static ionengine structure that we can reference.
+ * Instead we call a method which allocates the required ioengine
+ * structure.
+ */
+ if (!ops) {
+ get_ioengine_t get_ioengine = dlsym(dlhandle, "get_ioengine");
+ if (get_ioengine)
+ get_ioengine(&ops);
+ }
+
if (!ops) {
td_vmsg(td, -1, dlerror(), "dlsym");
dlclose(dlhandle);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] engines/null: allow build as external C++ ioengine
2014-02-12 19:13 [PATCH 1/2] Introduce get_ioengine for external engines Daniel Gollub
@ 2014-02-12 19:13 ` Daniel Gollub
2014-02-13 4:13 ` Jens Axboe
2014-02-13 4:12 ` [PATCH 1/2] Introduce get_ioengine for external engines Jens Axboe
1 sibling, 1 reply; 5+ messages in thread
From: Daniel Gollub @ 2014-02-12 19:13 UTC (permalink / raw)
To: fio; +Cc: Daniel Gollub
In first place to have a simple test candidate for external
ioengines using get_ioengine() method for retriving the
io_engine struct.
Can be compiled with:
g++ -O2 -g -shared -rdynamic -fPIC -o null.so null.c -DFIO_EXTERNAL_ENGINE
Signed-off-by: Daniel Gollub <d.gollub@telekom.de>
---
engines/null.c | 46 +++++++++++++++++++++++++++++++++++++++-------
1 file changed, 39 insertions(+), 7 deletions(-)
diff --git a/engines/null.c b/engines/null.c
index bf7885e..9f9d850 100644
--- a/engines/null.c
+++ b/engines/null.c
@@ -4,6 +4,10 @@
* IO engine that doesn't do any real IO transfers, it just pretends to.
* The main purpose is to test fio itself.
*
+ * It also can act as external C++ engine - compiled with:
+ *
+ * g++ -O2 -g -shared -rdynamic -fPIC -o null.so null.c -DFIO_EXTERNAL_ENGINE
+ *
*/
#include <stdio.h>
#include <stdlib.h>
@@ -21,7 +25,7 @@ struct null_data {
static struct io_u *fio_null_event(struct thread_data *td, int event)
{
- struct null_data *nd = td->io_ops->data;
+ struct null_data *nd = (struct null_data *) td->io_ops->data;
return nd->io_us[event];
}
@@ -30,7 +34,7 @@ static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
unsigned int fio_unused max,
struct timespec fio_unused *t)
{
- struct null_data *nd = td->io_ops->data;
+ struct null_data *nd = (struct null_data *) td->io_ops->data;
int ret = 0;
if (min_events) {
@@ -43,10 +47,12 @@ static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
static int fio_null_commit(struct thread_data *td)
{
- struct null_data *nd = td->io_ops->data;
+ struct null_data *nd = (struct null_data *) td->io_ops->data;
if (!nd->events) {
+#ifndef FIO_EXTERNAL_ENGINE
io_u_mark_submit(td, nd->queued);
+#endif
nd->events = nd->queued;
nd->queued = 0;
}
@@ -56,7 +62,7 @@ static int fio_null_commit(struct thread_data *td)
static int fio_null_queue(struct thread_data *td, struct io_u *io_u)
{
- struct null_data *nd = td->io_ops->data;
+ struct null_data *nd = (struct null_data *) td->io_ops->data;
fio_ro_check(td, io_u);
@@ -77,7 +83,7 @@ static int fio_null_open(struct thread_data fio_unused *td,
static void fio_null_cleanup(struct thread_data *td)
{
- struct null_data *nd = td->io_ops->data;
+ struct null_data *nd = (struct null_data *) td->io_ops->data;
if (nd) {
if (nd->io_us)
@@ -88,12 +94,12 @@ static void fio_null_cleanup(struct thread_data *td)
static int fio_null_init(struct thread_data *td)
{
- struct null_data *nd = malloc(sizeof(*nd));
+ struct null_data *nd = (struct null_data *) malloc(sizeof(*nd));
memset(nd, 0, sizeof(*nd));
if (td->o.iodepth != 1) {
- nd->io_us = malloc(td->o.iodepth * sizeof(struct io_u *));
+ nd->io_us = (struct io_u **) malloc(td->o.iodepth * sizeof(struct io_u *));
memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *));
} else
td->io_ops->flags |= FIO_SYNCIO;
@@ -102,6 +108,7 @@ static int fio_null_init(struct thread_data *td)
return 0;
}
+#ifndef __cplusplus
static struct ioengine_ops ioengine = {
.name = "null",
.version = FIO_IOOPS_VERSION,
@@ -124,3 +131,28 @@ static void fio_exit fio_null_unregister(void)
{
unregister_ioengine(&ioengine);
}
+
+#else
+
+#ifdef FIO_EXTERNAL_ENGINE
+extern "C" {
+void get_ioengine(struct ioengine_ops **ioengine_ptr) {
+ struct ioengine_ops *ioengine;
+ *ioengine_ptr = (struct ioengine_ops *) malloc(sizeof(struct ioengine_ops));
+ ioengine = *ioengine_ptr;
+
+ strcpy(ioengine->name, "cpp_null");
+ ioengine->version = FIO_IOOPS_VERSION;
+ ioengine->queue = fio_null_queue;
+ ioengine->commit = fio_null_commit;
+ ioengine->getevents = fio_null_getevents;
+ ioengine->event = fio_null_event;
+ ioengine->init = fio_null_init;
+ ioengine->cleanup = fio_null_cleanup;
+ ioengine->open_file = fio_null_open;
+ ioengine->flags = FIO_DISKLESSIO;
+}
+}
+#endif /* FIO_EXTERNAL_ENGINE */
+
+#endif /* __cplusplus */
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] Introduce get_ioengine for external engines
2014-02-12 19:13 [PATCH 1/2] Introduce get_ioengine for external engines Daniel Gollub
2014-02-12 19:13 ` [PATCH 2/2] engines/null: allow build as external C++ ioengine Daniel Gollub
@ 2014-02-13 4:12 ` Jens Axboe
1 sibling, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2014-02-13 4:12 UTC (permalink / raw)
To: Daniel Gollub, fio; +Cc: Daniel Gollub
On 2014-02-12 12:13, Daniel Gollub wrote:
> This makes life easier for plugins written in C++
> since they do not need to deal with struct initilization issues
> with the ioengine_ops symbol.
>
> With g++ a non-static ioengine_ops in global scope like this:
>
> struct ioengine_ops ioengine = {
> .name = "null",
> .version = FIO_IOOPS_VERSION,
> .queue = fio_null_queue,
> .commit = fio_null_commit,
> };
>
> Results in:
>
> cpp_null2.cc: At global scope:
> cpp_null2.cc:112:1: error: C99 designator ‘name’ outside aggregate initializer
> cpp_null2.cc:112:1: sorry, unimplemented: non-trivial designated initializers not supported
> cpp_null2.cc:112:1: sorry, unimplemented: non-trivial designated initializers not supported
> cpp_null2.cc:112:1: sorry, unimplemented: non-trivial designated initializers not supported
> cpp_null2.cc:112:1: sorry, unimplemented: non-trivial designated initializers not supported
> $
>
> Example get_iongine() symbol usage:
>
> ---8<---
> extern "C" {
> void get_ioengine(struct ioengine_ops **ioengine_ptr) {
> struct ioengine_ops *ioengine;
> *ioengine_ptr = (struct ioengine_ops *) malloc(sizeof(struct ioengine_ops));
> ioengine = *ioengine_ptr;
>
> strcpy(ioengine->name, "cpp_null");
> ioengine->version = FIO_IOOPS_VERSION;
> ioengine->queue = fio_null_queue;
> ioengine->commit = fio_null_commit;
> ioengine->getevents = fio_null_getevents;
> ioengine->event = fio_null_event;
> ioengine->init = fio_null_init;
> ioengine->cleanup = fio_null_cleanup;
> ioengine->open_file = fio_null_open;
> ioengine->flags = FIO_DISKLESSIO;
> }
> }
> --->8---
>
> Signed-off-by: Daniel Gollub <d.gollub@telekom.de>
> ---
> ioengines.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/ioengines.c b/ioengines.c
> index d71e372..c080da3 100644
> --- a/ioengines.c
> +++ b/ioengines.c
> @@ -90,6 +90,7 @@ static struct ioengine_ops *dlopen_ioengine(struct thread_data *td,
> {
> struct ioengine_ops *ops;
> void *dlhandle;
> + typedef void (*get_ioengine_t)(struct ioengine_ops **);
>
> dprint(FD_IO, "dload engine %s\n", engine_lib);
>
> @@ -107,6 +108,19 @@ static struct ioengine_ops *dlopen_ioengine(struct thread_data *td,
> ops = dlsym(dlhandle, engine_lib);
> if (!ops)
> ops = dlsym(dlhandle, "ioengine");
> +
> + /*
> + * For some external engines (like C++ ones) it is not that trivial
> + * to provide a non-static ionengine structure that we can reference.
> + * Instead we call a method which allocates the required ioengine
> + * structure.
> + */
> + if (!ops) {
> + get_ioengine_t get_ioengine = dlsym(dlhandle, "get_ioengine");
> + if (get_ioengine)
> + get_ioengine(&ops);
> + }
> +
> if (!ops) {
> td_vmsg(td, -1, dlerror(), "dlsym");
> dlclose(dlhandle);
>
This looks fine, but lets put that typedef in ioengine.h instead.
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] engines/null: allow build as external C++ ioengine
2014-02-12 19:13 ` [PATCH 2/2] engines/null: allow build as external C++ ioengine Daniel Gollub
@ 2014-02-13 4:13 ` Jens Axboe
2014-02-13 6:25 ` Daniel Gollub
0 siblings, 1 reply; 5+ messages in thread
From: Jens Axboe @ 2014-02-13 4:13 UTC (permalink / raw)
To: Daniel Gollub, fio; +Cc: Daniel Gollub
On 2014-02-12 12:13, Daniel Gollub wrote:
> In first place to have a simple test candidate for external
> ioengines using get_ioengine() method for retriving the
> io_engine struct.
>
> Can be compiled with:
>
> g++ -O2 -g -shared -rdynamic -fPIC -o null.so null.c -DFIO_EXTERNAL_ENGINE
I'm assuming this is just an example of how you'd build your external
engine? Look OK to me with that in mind.
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] engines/null: allow build as external C++ ioengine
2014-02-13 4:13 ` Jens Axboe
@ 2014-02-13 6:25 ` Daniel Gollub
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Gollub @ 2014-02-13 6:25 UTC (permalink / raw)
To: Jens Axboe; +Cc: fio, Daniel Gollub
On Wed, 12 Feb 2014 21:13:14 -0700, Jens Axboe wrote:
> On 2014-02-12 12:13, Daniel Gollub wrote:
> > In first place to have a simple test candidate for external
> > ioengines using get_ioengine() method for retriving the
> > io_engine struct.
> >
> > Can be compiled with:
> >
> > g++ -O2 -g -shared -rdynamic -fPIC -o null.so null.c
> > -DFIO_EXTERNAL_ENGINE
>
> I'm assuming this is just an example of how you'd build your external
> engine? Look OK to me with that in mind.
>
Yes it is. I although thought about integrating the build (of the null
C++/external variant) as kind of a build/compile test (not by default)
so we can spot changes on fio.h (or headers which are included by fio.h)
which break builds for external C++ based ioengines.
Something like ./configure --example-external-ioengines which
would also build skeleton_external (plain C) and cpp_null.so (if g++ is
available).
--
Daniel Gollub
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-02-13 6:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-12 19:13 [PATCH 1/2] Introduce get_ioengine for external engines Daniel Gollub
2014-02-12 19:13 ` [PATCH 2/2] engines/null: allow build as external C++ ioengine Daniel Gollub
2014-02-13 4:13 ` Jens Axboe
2014-02-13 6:25 ` Daniel Gollub
2014-02-13 4:12 ` [PATCH 1/2] Introduce get_ioengine for external engines Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox