summaryrefslogtreecommitdiffstats
path: root/src/include/util
diff options
context:
space:
mode:
authorDoug Gilbert <dgilbert@us.ibm.com>2012-07-12 12:17:29 -0500
committerA. Patrick Williams III <iawillia@us.ibm.com>2012-07-28 13:04:29 -0500
commitac9ad22f261cd391c0d5163e82ff02ae4929f820 (patch)
tree5e6ab5b19095fdb5de9ce7d69517e9de9a27aa49 /src/include/util
parentf6b5db9e2298aa22b148f5a72d64a5564040c61a (diff)
downloadtalos-hostboot-ac9ad22f261cd391c0d5163e82ff02ae4929f820.tar.gz
talos-hostboot-ac9ad22f261cd391c0d5163e82ff02ae4929f820.zip
Reduce timeslice for idle task based on wake time of sleeping tasks
RTC: 43738 Change-Id: I91c2bfe57bba04a02dd5169542de8e76e1654ae8 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/1387 Tested-by: Jenkins Server Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com> Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/include/util')
-rw-r--r--src/include/util/locked/pqueue.H283
1 files changed, 161 insertions, 122 deletions
diff --git a/src/include/util/locked/pqueue.H b/src/include/util/locked/pqueue.H
index 8e21a01d8..2a6324fe6 100644
--- a/src/include/util/locked/pqueue.H
+++ b/src/include/util/locked/pqueue.H
@@ -1,25 +1,26 @@
-// IBM_PROLOG_BEGIN_TAG
-// This is an automatically generated prolog.
-//
-// $Source: src/include/util/locked/pqueue.H $
-//
-// IBM CONFIDENTIAL
-//
-// COPYRIGHT International Business Machines Corp. 2010 - 2011
-//
-// p1
-//
-// Object Code Only (OCO) source materials
-// Licensed Internal Code Source Materials
-// IBM HostBoot Licensed Internal Code
-//
-// The source code for this program is not published or other-
-// wise divested of its trade secrets, irrespective of what has
-// been deposited with the U.S. Copyright Office.
-//
-// Origin: 30
-//
-// IBM_PROLOG_END
+/* IBM_PROLOG_BEGIN_TAG
+ * This is an automatically generated prolog.
+ *
+ * $Source: src/include/util/locked/pqueue.H $
+ *
+ * IBM CONFIDENTIAL
+ *
+ * COPYRIGHT International Business Machines Corp. 2010-2012
+ *
+ * p1
+ *
+ * Object Code Only (OCO) source materials
+ * Licensed Internal Code Source Materials
+ * IBM HostBoot Licensed Internal Code
+ *
+ * The source code for this program is not published or other-
+ * wise divested of its trade secrets, irrespective of what has
+ * been deposited with the U.S. Copyright Office.
+ *
+ * Origin: 30
+ *
+ * IBM_PROLOG_END_TAG
+ */
#ifndef __UTIL_LOCKED_PQUEUE_H
#define __UTIL_LOCKED_PQUEUE_H
@@ -29,108 +30,146 @@ namespace Util
{
namespace Locked
{
- template <typename _T, typename _K,
- bool locked = false, typename _S = int>
- class PQueue : public Queue<_T, locked, _S>
- {
- public:
- void insert(_T*);
- _T* remove_if(_K&);
-
- private:
- void bubbleUp(_T*);
- };
-
- template <typename _T, typename _K, bool locked, typename _S>
- void PQueue<_T,_K,locked,_S>::insert(_T* item)
- {
- this->__lock();
-
- if (this->head == NULL)
- {
- item->next = item->prev = NULL;
- this->head = this->tail = item;
- }
- else
- {
- item->prev = NULL;
- item->next = this->head;
- this->head = this->head->prev = item;
-
- bubbleUp(item);
- }
-
- this->__unlock();
- }
-
- template <typename _T, typename _K, bool locked, typename _S>
- _T* PQueue<_T,_K,locked,_S>::remove_if(_K& key)
- {
- _T* item = NULL;
-
- this->__lock();
-
- if ((this->tail != NULL) && (this->tail->key <= key))
- {
- item = this->tail;
- if (this->head == this->tail)
- this->head = this->tail = NULL;
- else
- this->tail = item->prev;
+ template <typename _T, typename _K,
+ bool locked = false, typename _S = int>
+ class PQueue : public Queue<_T, locked, _S>
+ {
+ public:
+ void insert(_T*);
+ _T* remove_if(_K&);
+ _T* front();
+
+ private:
+ void bubbleUp(_T*);
+ };
+
+ // SFINAE template to ensure compile fails if functions which are not
+ // SMP-safe are used on a 'locked' instance.
+ template<bool locked>
+ class __verify_pqueue_is_smp_safe
+ {
+ public:
+ __verify_pqueue_is_smp_safe()
+ {
+ class __util_locked_pqueue_is_not_smp_safe;
+ __util_locked_pqueue_is_not_smp_safe();
+ }
+ };
+
+ // SFINAE template implementation to allow certain functions when the
+ // instance is not 'locked', assuming that caller is ensuring safety
+ // in some other way.
+ template<>
+ class __verify_pqueue_is_smp_safe<false>
+ {
+ public:
+ __verify_pqueue_is_smp_safe()
+ {
+ }
+ };
+
+
+ template <typename _T, typename _K, bool locked, typename _S>
+ void PQueue<_T,_K,locked,_S>::insert(_T* item)
+ {
+ this->__lock();
+
+ if (this->head == NULL)
+ {
+ item->next = item->prev = NULL;
+ this->head = this->tail = item;
+ }
+ else
+ {
+ item->prev = NULL;
+ item->next = this->head;
+ this->head = this->head->prev = item;
+
+ bubbleUp(item);
+ }
+
+ this->__unlock();
+ }
+
+ template <typename _T, typename _K, bool locked, typename _S>
+ _T* PQueue<_T,_K,locked,_S>::remove_if(_K& key)
+ {
+ _T* item = NULL;
+
+ this->__lock();
+
+ if ((this->tail != NULL) && (this->tail->key <= key))
+ {
+ item = this->tail;
+ if (this->head == this->tail)
+ this->head = this->tail = NULL;
+ else
+ this->tail = item->prev;
+
+ if (item->prev)
+ item->prev->next = NULL;
+ }
+
+ this->__unlock();
+
+ return item;
+ }
+
+
+ template <typename _T, typename _K, bool locked, typename _S>
+ void PQueue<_T,_K,locked,_S>::bubbleUp(_T* item)
+ {
+ if (!item->next)
+ return;
+
+ if (item->next->key <= item->key)
+ return;
+
+ if (this->head == item)
+ this->head = item->next;
+ if (this->tail == item->next)
+ this->tail = item;
+
+ _T* temp = item->next;
+
+ if (temp->next)
+ {
+ temp->next->prev = item;
+ item->next = item->next->next;
+ }
+ else
+ {
+ item->next = NULL;
+ }
if (item->prev)
- item->prev->next = NULL;
- }
-
- this->__unlock();
-
- return item;
- }
-
-
- template <typename _T, typename _K, bool locked, typename _S>
- void PQueue<_T,_K,locked,_S>::bubbleUp(_T* item)
- {
- if (!item->next)
- return;
-
- if (item->next->key <= item->key)
- return;
-
- if (this->head == item)
- this->head = item->next;
- if (this->tail == item->next)
- this->tail = item;
-
- _T* temp = item->next;
-
- if (temp->next)
- {
- temp->next->prev = item;
- item->next = item->next->next;
- }
- else
- {
- item->next = NULL;
- }
-
- if (item->prev)
- {
- item->prev->next = temp;
- temp->prev = item->prev;
- }
- else
- {
- temp->prev = NULL;
- }
-
- temp->next = item;
- item->prev = temp;
-
- bubbleUp(item);
- }
-
-
+ {
+ item->prev->next = temp;
+ temp->prev = item->prev;
+ }
+ else
+ {
+ temp->prev = NULL;
+ }
+
+ temp->next = item;
+ item->prev = temp;
+
+ bubbleUp(item);
+ }
+
+
+ template <typename _T, typename _K, bool locked, typename _S>
+ _T* PQueue<_T, _K,locked,_S>::front()
+ {
+ // Entirely not SMP-safe to return a pointer to a node if
+ // we are a locking instance. If we aren't locking we
+ // have to assume that the caller is ensuring SMP-safety
+ // globally in some other way. Use SFINAE technique to
+ // ensure front() fails on locked lists.
+ __verify_pqueue_is_smp_safe<locked>();
+ return this->tail;
+ }
};
};
OpenPOWER on IntegriCloud