[Cbe-oss-dev] [PATCH 17/28]MARS/base: cache workload context

Yuji Mano yuji.mano at am.sony.com
Fri Feb 6 13:32:03 EST 2009


This patch provides a new kernel syscall query that allows the workload module
to know whether the MPU storage context state is cached.

* kernel id is reduced from uint32_t to uint16_t
* kernel id of the kernel that is running or most recently ran the workload is
  stored in the workload bits
* mars_module_workload_query(MARS_QUERY_IS_CACHED) when the following conditions
  are satisfied:

    1) workload id specified is the workload id currently being run
    2) workload id specified is the workload the current kernel ran last time
    3) current kernel is the last kernel to run the specified workload

    Note: Conditions (2) and (3) are different because the current kernel may
          have ran the workload last time, but the workload may have been ran
          by another kernel since then, OR current kernel may have been the last
          kernel to run the workload, but may have ran another workload since
          then.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 base/include/mpu/mars/module.h            |    7 ++++---
 base/src/common/kernel_internal_types.h   |    9 +++++----
 base/src/common/workload_internal_types.h |   20 +++++++++++---------
 base/src/host/lib/workload_queue.c        |    2 ++
 base/src/mpu/kernel/kernel.c              |   19 +++++++++++++++++--
 base/src/mpu/lib/module.c                 |    2 +-
 6 files changed, 40 insertions(+), 19 deletions(-)

--- a/base/include/mpu/mars/module.h
+++ b/base/include/mpu/mars/module.h
@@ -92,9 +92,9 @@ uint64_t mars_module_get_mars_context_ea
  * \brief <b>[MPU]</b> Gets id of kernel that the module is being executed on.
  *
  * \return
- *	uint32_t		- id of MARS kernel
+ *	uint16_t		- id of MARS kernel
  */
-uint32_t mars_module_get_kernel_id(void);
+uint16_t mars_module_get_kernel_id(void);
 
 /**
  * \ingroup group_mars_workload_module
@@ -130,7 +130,8 @@ struct mars_workload_context *mars_modul
  * These are the query types you can pass into \ref mars_module_workload_query
  */
 enum {
-	MARS_QUERY_IS_INITIALIZED = 0,	/**< query if workload is initialized */
+	MARS_QUERY_IS_CACHED = 0,	/**< query if workload is cached */
+	MARS_QUERY_IS_INITIALIZED,	/**< query if workload is initialized */
 	MARS_QUERY_IS_READY,		/**< query if workload is ready */
 	MARS_QUERY_IS_WAITING,		/**< query if workload is waiting */
 	MARS_QUERY_IS_RUNNING,		/**< query if workload is running */
--- a/base/src/common/kernel_internal_types.h
+++ b/base/src/common/kernel_internal_types.h
@@ -42,6 +42,8 @@
 
 #include "mars/mutex_types.h"
 
+#define MARS_KERNEL_ID_NONE			0xffff
+
 #define MARS_KERNEL_STATUS_BUSY			0x0
 #define MARS_KERNEL_STATUS_IDLE			0x1
 #define MARS_KERNEL_STATUS_EXIT			0x2
@@ -58,7 +60,7 @@
 struct mars_kernel_syscalls {
 	uint32_t                       (*get_ticks)(void);
 	uint64_t                       (*get_mars_context_ea)(void);
-	uint32_t                       (*get_kernel_id)(void);
+	uint16_t                       (*get_kernel_id)(void);
 	uint16_t                       (*get_workload_id)(void);
 	struct mars_workload_context * (*get_workload)(void);
 	struct mars_workload_context * (*get_workload_by_id)(uint16_t id);
@@ -88,12 +90,11 @@ struct mars_kernel_ticks {
 
 /* mars kernel parameters */
 struct mars_kernel_params {
-	uint32_t kernel_id;
-	uint32_t pad1;
 	uint64_t mars_context_ea;
 	uint64_t workload_queue_ea;
 	struct mars_kernel_ticks kernel_ticks;
-	uint8_t pad2[MARS_KERNEL_PARAMS_SIZE - 32];
+	uint16_t kernel_id;
+	uint8_t pad[MARS_KERNEL_PARAMS_SIZE - 26];
 } __attribute__((aligned(MARS_KERNEL_PARAMS_ALIGN)));
 
 /* mars module entry */
--- a/base/src/common/workload_internal_types.h
+++ b/base/src/common/workload_internal_types.h
@@ -107,25 +107,27 @@
 
 /*
  * MARS workload queue block workload bits (64-bits)
- * ------------------------------------------------------------------
- * |[63...60]|[59....52]|[51....33]|[  32  ]|[31.....16]|[15......0]|
- * ------------------------------------------------------------------
- * |  4-bits |  8-bits  |  19-bits |  1-bit |  16-bits  |  16-bits  |
- * ------------------------------------------------------------------
- * |  STATE  | PRIORITY | RESERVED | SIGNAL |  WAIT_ID  |  COUNTER  |
- * ------------------------------------------------------------------
+ * ----------------------------------------------------------------------------
+ * |[63...60]|[59....52]|[51....36]|[35...33]|[  32  ]|[31.....16]|[15......0]|
+ * ----------------------------------------------------------------------------
+ * |  4-bits |  8-bits  |  16-bits |  3-bits |  1-bit |  16-bits  |  16-bits  |
+ * ----------------------------------------------------------------------------
+ * |  STATE  | PRIORITY |  COUNTER |   PAD   | SIGNAL |  WAIT_ID  | KERNEL_ID |
+ * ----------------------------------------------------------------------------
  */
 #define MARS_BITS_SHIFT_WORKLOAD_STATE		60
 #define MARS_BITS_SHIFT_WORKLOAD_PRIORITY	52
+#define MARS_BITS_SHIFT_WORKLOAD_COUNTER	36
 #define MARS_BITS_SHIFT_WORKLOAD_SIGNAL		32
 #define MARS_BITS_SHIFT_WORKLOAD_WAIT_ID	16
-#define MARS_BITS_SHIFT_WORKLOAD_COUNTER	0
+#define MARS_BITS_SHIFT_WORKLOAD_KERNEL_ID	0
 
 #define MARS_BITS_MASK_WORKLOAD_STATE		0xf000000000000000ULL
 #define MARS_BITS_MASK_WORKLOAD_PRIORITY	0x0ff0000000000000ULL
+#define MARS_BITS_MASK_WORKLOAD_COUNTER		0x000ffff000000000ULL
 #define MARS_BITS_MASK_WORKLOAD_SIGNAL		0x0000000100000000ULL
 #define MARS_BITS_MASK_WORKLOAD_WAIT_ID		0x00000000ffff0000ULL
-#define MARS_BITS_MASK_WORKLOAD_COUNTER		0x000000000000ffffULL
+#define MARS_BITS_MASK_WORKLOAD_KERNEL_ID	0x000000000000ffffULL
 
 #define MARS_BITS_GET(bits, name)  \
 	((*(bits) & MARS_BITS_MASK_##name) >> MARS_BITS_SHIFT_##name)
--- a/base/src/host/lib/workload_queue.c
+++ b/base/src/host/lib/workload_queue.c
@@ -256,6 +256,8 @@ static int alloc_block(uint64_t block_ea
 		    MARS_WORKLOAD_STATE_NONE) {
 			MARS_BITS_SET(&bits, WORKLOAD_STATE,
 				      MARS_WORKLOAD_STATE_ADDING);
+			MARS_BITS_SET(&bits, WORKLOAD_KERNEL_ID,
+				      MARS_KERNEL_ID_NONE);
 			mars_ea_put_uint64(get_block_bits_ea(block_ea, index),
 					   bits);
 			ret = index;
--- a/base/src/mpu/kernel/kernel.c
+++ b/base/src/mpu/kernel/kernel.c
@@ -60,9 +60,10 @@ static struct mars_workload_queue_block 
 
 /* workload */
 static struct mars_workload_context workload;
-static uint8_t workload_state;
 static uint16_t workload_id;
 static uint64_t workload_ea;
+static uint8_t workload_state;
+static uint8_t workload_cached;
 
 /* workload to schedule */
 static struct mars_workload_context schedule_workload;
@@ -258,7 +259,7 @@ static uint64_t get_mars_context_ea(void
 	return kernel_params.mars_context_ea;
 }
 
-static uint32_t get_kernel_id(void)
+static uint16_t get_kernel_id(void)
 {
 	return kernel_params.kernel_id;
 }
@@ -421,6 +422,8 @@ static int workload_query(uint16_t id, i
 	uint64_t bits = get_block_bits(id);
 
 	switch (query) {
+	case MARS_QUERY_IS_CACHED:
+		return (id == workload_id && workload_cached);
 	case MARS_QUERY_IS_INITIALIZED:
 		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) !=
 			MARS_WORKLOAD_STATE_NONE);
@@ -773,6 +776,18 @@ static int search_block(int block, int r
 		MARS_BITS_SET(&queue_block.bits[index], WORKLOAD_COUNTER,
 			      MARS_WORKLOAD_COUNTER_MIN);
 
+		/* check if this kernel ran this workload most recently */
+		workload_cached =
+			(workload_id ==
+				MARS_WORKLOAD_PER_BLOCK * block + index) &&
+			(kernel_params.kernel_id ==
+				MARS_BITS_GET(&queue_block.bits[index],
+					      WORKLOAD_KERNEL_ID));
+
+		/* set the kernel id of this kernel into block bits */
+		MARS_BITS_SET(&queue_block.bits[index], WORKLOAD_KERNEL_ID,
+			      kernel_params.kernel_id);
+
 		/* update queue header bits and reset block counter */
 		update_header_bits(block);
 		update_header_bits_counter(block, 1);
--- a/base/src/mpu/lib/module.c
+++ b/base/src/mpu/lib/module.c
@@ -84,7 +84,7 @@ uint64_t mars_module_get_mars_context_ea
 	return (*kernel_syscalls->get_mars_context_ea)();
 }
 
-uint32_t mars_module_get_kernel_id(void)
+uint16_t mars_module_get_kernel_id(void)
 {
 	return (*kernel_syscalls->get_kernel_id)();
 }







More information about the cbe-oss-dev mailing list