pthreadpool: Add a simple benchmark
authorVolker Lendecke <vl@samba.org>
Mon, 24 Mar 2014 09:40:20 +0000 (09:40 +0000)
committerJeremy Allison <jra@samba.org>
Thu, 27 Mar 2014 05:06:11 +0000 (06:06 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/torture/bench_pthreadpool.c [new file with mode: 0644]
source3/torture/proto.h
source3/torture/torture.c
source3/wscript_build

diff --git a/source3/torture/bench_pthreadpool.c b/source3/torture/bench_pthreadpool.c
new file mode 100644 (file)
index 0000000..ee0d203
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Little pthreadpool benchmark
+ *
+ * Copyright (C) Volker Lendecke 2014
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "lib/pthreadpool/pthreadpool.h"
+#include "proto.h"
+
+extern int torture_numops;
+
+static void null_job(void *private_data)
+{
+       return;
+}
+
+bool run_bench_pthreadpool(int dummy)
+{
+       struct pthreadpool *pool;
+       int i, ret;
+
+       ret = pthreadpool_init(1, &pool);
+       if (ret != 0) {
+               d_fprintf(stderr, "pthreadpool_init failed: %s\n",
+                         strerror(ret));
+               return false;
+       }
+
+       for (i=0; i<torture_numops; i++) {
+               int jobid;
+
+               ret = pthreadpool_add_job(pool, 0, null_job, NULL);
+               if (ret != 0) {
+                       d_fprintf(stderr, "pthreadpool_add_job failed: %s\n",
+                                 strerror(ret));
+                       break;
+               }
+               ret = pthreadpool_finished_job(pool, &jobid);
+               if (ret != 0) {
+                       d_fprintf(stderr, "pthreadpool_finished_job failed: %s\n",
+                                 strerror(ret));
+                       break;
+               }
+       }
+
+       pthreadpool_destroy(pool);
+
+       return (ret == 0);
+}
index 2b27289d4744b5e0079aadc99343ab672b8e6740..3673d98def39c3367310ff62fa8671e77f073e33 100644 (file)
@@ -112,5 +112,6 @@ bool run_dbwrap_watch1(int dummy);
 bool run_idmap_tdb_common_test(int dummy);
 bool run_local_dbwrap_ctdb(int dummy);
 bool run_qpathinfo_bufsize(int dummy);
+bool run_bench_pthreadpool(int dummy);
 
 #endif /* __TORTURE_H__ */
index 340f754d54fbfe54bed2ea55dd1e5d8d059a42f4..61e9338d3d654a76719727ff754d54633bd1bfda 100644 (file)
@@ -9593,6 +9593,7 @@ static struct {
        { "local-tdb-opener", run_local_tdb_opener, 0 },
        { "local-tdb-writer", run_local_tdb_writer, 0 },
        { "LOCAL-DBWRAP-CTDB", run_local_dbwrap_ctdb, 0 },
+       { "LOCAL-BENCH-PTHREADPOOL", run_bench_pthreadpool, 0 },
        { "qpathinfo-bufsize", run_qpathinfo_bufsize, 0 },
        {NULL, NULL, 0}};
 
index 02a5c7d58a7f30879652cd866181a7bdd1d13c65..ca53951889b954862d9dff95243e42dc33822251 100755 (executable)
@@ -1243,6 +1243,7 @@ bld.SAMBA3_BINARY('smbtorture' + bld.env.suffix3,
                  torture/test_dbwrap_ctdb.c
                  torture/test_buffersize.c
                  torture/t_strappend.c
+                 torture/bench_pthreadpool.c
                  torture/wbc_async.c''',
                  deps='''
                  talloc