From 713567509987306eeb37843bec105a30778fd3ab Mon Sep 17 00:00:00 2001 From: Luis Remis Date: Wed, 30 Jan 2019 06:28:47 -0800 Subject: [PATCH 1/2] Remove old, outdated examples --- examples/pyClient/sendQueryFromFile.py | 50 -------------------------- examples/pyClient/threadClient.py | 45 ----------------------- 2 files changed, 95 deletions(-) delete mode 100644 examples/pyClient/sendQueryFromFile.py delete mode 100644 examples/pyClient/threadClient.py diff --git a/examples/pyClient/sendQueryFromFile.py b/examples/pyClient/sendQueryFromFile.py deleted file mode 100644 index 8ff4715b..00000000 --- a/examples/pyClient/sendQueryFromFile.py +++ /dev/null @@ -1,50 +0,0 @@ -# -# The MIT License -# -# @copyright Copyright (c) 2017 Intel Corporation -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, -# merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -# ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -#! /usr/bin/python -from threading import Thread -import sys -import os -import urllib -import time -import json -import unittest - -import vdms - - -if len(sys.argv) != 2: - print "You must provide a json file" -else: - hostname = "localhost" - - db = vdms.VDMS() - db.connect(hostname) - - with open(sys.argv[1]) as json_file: - query = json.load(json_file) - - response, img_array = db.query(query) - print vdms.aux_print_json(response) \ No newline at end of file diff --git a/examples/pyClient/threadClient.py b/examples/pyClient/threadClient.py deleted file mode 100644 index 4359a1b9..00000000 --- a/examples/pyClient/threadClient.py +++ /dev/null @@ -1,45 +0,0 @@ -# -# The MIT License -# -# @copyright Copyright (c) 2017 Intel Corporation -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, -# merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -# ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -#! /usr/bin/python -from threading import Thread -import sys -import os -import urllib -import time - -import vdms # Import vdms - -def clientThread(thId): - - response = vdms.query( - "{HERE GOES YOUR JSON QUERY from Th " + str(thId) + "}") - - print "Thread " + str(thId) + ": " + response - -for i in range(1,1000): - thread = Thread(target=clientThread,args=(i,) ) - thread.start() - From 977076b6a3f939383c8d579d4abbb1a128933808 Mon Sep 17 00:00:00 2001 From: Luis Remis Date: Wed, 30 Jan 2019 07:38:34 -0800 Subject: [PATCH 2/2] Remove arch.h and rwlock.h files --- src/RWLock.h | 198 --------------------------------------------------- src/arch.h | 58 --------------- 2 files changed, 256 deletions(-) delete mode 100644 src/RWLock.h delete mode 100644 src/arch.h diff --git a/src/RWLock.h b/src/RWLock.h deleted file mode 100644 index a17799c3..00000000 --- a/src/RWLock.h +++ /dev/null @@ -1,198 +0,0 @@ -/** - * @file RWLock.h - * - * @section LICENSE - * - * The MIT License - * - * @copyright Copyright (c) 2017 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, - * merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -#pragma once -#include -#include -#include -#include - -#include "arch.h" -#include "ExceptionsCommand.h" - -// All locking structures live in DRAM. We use stripe locks -// to balance out the space used by locks for a large database -// vs. parallelism. -namespace VDMS { - class RWLock - { - static const uint16_t LOCK_READER_MASK = 0x7fff; - static const uint16_t READER_INCR = 1; - static const uint16_t WRITER_LOCK_BIT = 15; - static const uint16_t WRITE_LOCK = 1UL << WRITER_LOCK_BIT; - - // Backoff variables. - // *** Tune experimentally - static const size_t MIN_BACKOFF_DELAY = 100000; - static const size_t MAX_BACKOFF_DELAY = 500000000; - - uint16_t xadd(volatile uint16_t &m, uint16_t v) - { return ::xadd(m, v); } - void atomic_and(volatile uint16_t &m, uint16_t v) - { ::atomic_and(m, v); } - - volatile uint16_t _rw_lock; - const unsigned _max_attempts; - - // Ideas from here: https://geidav.wordpress.com/tag/exponential-back-off - void backoff(size_t &cur_max_delay) - { - std::random_device rd; - thread_local std::uniform_int_distribution dist; - - // The simplest pseudo-random number generator that gives an int. - thread_local std::minstd_rand gen(rd()); - - size_t delay = cur_max_delay; - size_t temp = 2 * cur_max_delay; - cur_max_delay = (temp < MAX_BACKOFF_DELAY) ? temp : MAX_BACKOFF_DELAY; - const size_t count = dist(gen, decltype(dist)::param_type{delay, cur_max_delay}); - for (size_t i = 0; i < count; ++i) - pause(); - } - - public: - static const unsigned MAX_ATTEMPTS = 10; - - RWLock(unsigned max_attempts) : _rw_lock(0), _max_attempts(max_attempts) {} - - void read_lock() - { - size_t cur_max_delay = MIN_BACKOFF_DELAY; - unsigned attempts = 0; - - while (1) { - uint16_t r = xadd(_rw_lock, READER_INCR); - if((r & LOCK_READER_MASK) == LOCK_READER_MASK) // if r was already maxed out - throw ExceptionCommand(LockError); // distinguish this from timeout. - - // Check if we get lock w/o any active writers - if ((r & WRITE_LOCK) == 0) - return; - xadd(_rw_lock, -READER_INCR); - - // Wait for any active writers - while (_rw_lock & WRITE_LOCK) { - if (++attempts > _max_attempts) - throw ExceptionCommand(LockTimeout); - backoff(cur_max_delay); - } - } - } - - void read_unlock() - { - if ((_rw_lock & LOCK_READER_MASK) == 0) - throw ExceptionCommand(LockError); // distinguish this from timeout. - xadd(_rw_lock, -READER_INCR); - } - - void write_lock() - { - size_t cur_max_delay = MIN_BACKOFF_DELAY; - unsigned attempts = 0; - - while (1) { - // Check if we get lock w/o any active writers - if (bts(_rw_lock, WRITER_LOCK_BIT) == 0) { - attempts = 0; - - // Wait for any active readers - while(_rw_lock & LOCK_READER_MASK) { - if (++attempts > _max_attempts) { - atomic_and(_rw_lock, LOCK_READER_MASK); - throw ExceptionCommand(LockTimeout); - } - backoff(cur_max_delay); - } - return; - } - - // Wait for any active writers - while (_rw_lock & WRITE_LOCK) { - if (++attempts > _max_attempts) { - throw ExceptionCommand(LockTimeout); - } - backoff(cur_max_delay); - } - } - } - - // This function should be called only when the caller already possesses - // a read lock. Rather than making this recursive, we are relying on the - // caller to use this correctly. - void upgrade_write_lock() - { - size_t cur_max_delay = MIN_BACKOFF_DELAY; - unsigned attempts = 0; - - while (1) { - // Check if we get lock w/o any active writers - if (bts(_rw_lock, WRITER_LOCK_BIT) == 0) { - attempts = 0; - - // Wait for any active readers - while ((_rw_lock & LOCK_READER_MASK) > 1) { - if (++attempts > _max_attempts) { - atomic_and(_rw_lock, LOCK_READER_MASK); - throw ExceptionCommand(LockTimeout); - } - backoff(cur_max_delay); - } - - // Don't need reader lock anymore - xadd(_rw_lock, -READER_INCR); - return; - } - - // Wait for any active writers - // Give this another extra attempt - while (_rw_lock & WRITE_LOCK) { - if (attempts++ > _max_attempts) { - throw ExceptionCommand(LockTimeout); - } - backoff(cur_max_delay); - } - } - } - - void write_unlock() - { - if((_rw_lock & WRITE_LOCK) == 0) - throw ExceptionCommand(LockError); // distinguish this from timeout. - atomic_and(_rw_lock, LOCK_READER_MASK); - } - - bool is_write_locked() { return _rw_lock & WRITE_LOCK; } - - uint16_t reader_count() const { return _rw_lock & LOCK_READER_MASK; } - }; -} diff --git a/src/arch.h b/src/arch.h deleted file mode 100644 index df5e9032..00000000 --- a/src/arch.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file arch.h - * - * @section LICENSE - * - * The MIT License - * - * @copyright Copyright (c) 2017 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -#pragma once - -#include - -template -static inline void atomic_and(volatile T &m, T v) - { asm volatile ("lock and%z0 %1, %0" : "+m"(m) : "ri"(v) : "memory"); } - -template -static inline bool bts(volatile T &m, int bit) -{ - bool result = 0; - __asm__ volatile ("lock bts%z1 %2, %1\n; setc %0" - : "=q"(result), "+m"(m) : "Ir"(T(bit)) : "memory", "cc"); - return result; -} - -template -static inline T xadd(volatile T &m, T v) -{ - T r = v; - asm volatile ("lock xadd %1, %0" : "+m"(m), "+r"(r)); - return r; -} - -static inline void pause() -{ - asm("pause"); -}