summaryrefslogtreecommitdiffstats
path: root/mboxd_windows.c
diff options
context:
space:
mode:
authorSuraj Jitindar Singh <sjitindarsingh@gmail.com>2017-04-12 14:26:47 +1000
committerSuraj Jitindar Singh <sjitindarsingh@gmail.com>2017-04-12 14:42:34 +1000
commitc29172e1734012af7a9b97c5170b9da6a571e343 (patch)
tree5c25e8ba96c68ea0a7539fc19612ec06b8909455 /mboxd_windows.c
parent04e8ffda0daaf1e0dd034a91b421bab2b3eb9723 (diff)
downloadphosphor-mboxd-c29172e1734012af7a9b97c5170b9da6a571e343.tar.gz
phosphor-mboxd-c29172e1734012af7a9b97c5170b9da6a571e343.zip
mboxd: Make window size and number optional command line parameters
The window size and number command line parameters are used to control the number of windows and the size of each of the windows in the window cache which the reserved memory region is divided between. Most people won't care about tuning these or just won't know what they refer to. Additionally in the event we change how the window cache works or allow a non-constant window size then the meaning of these becomes unclear. Daemon implementations may also choose to just not implement a cache so making these required parameters may hurt portability. Make the window size and number command line parameters optional rather than required so that they can be largly ignored while people who really care about tuning them can still do so. The default for now is to have windows of size 1MB and to map the entire reserved memory region. That is: number of windows = size of memory region / size of windows This means that the size of the reserved memory region can be reduced and the daemon will adapt to this. Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com> Change-Id: I7c7bbef6e5d31d1372ec3a755877cacc6c135cce
Diffstat (limited to 'mboxd_windows.c')
-rw-r--r--mboxd_windows.c71
1 files changed, 56 insertions, 15 deletions
diff --git a/mboxd_windows.c b/mboxd_windows.c
index fd46770..c64d19b 100644
--- a/mboxd_windows.c
+++ b/mboxd_windows.c
@@ -54,7 +54,7 @@
* @window: The window to initialise
* @size: The size of the window
*/
-void init_window_state(struct window_context *window, uint32_t size)
+static void init_window_state(struct window_context *window, uint32_t size)
{
window->mem = NULL;
window->flash_offset = FLASH_OFFSET_UNINIT;
@@ -69,7 +69,7 @@ void init_window_state(struct window_context *window, uint32_t size)
*
* Return: 0 on success otherwise negative error code
*/
-int init_window_mem(struct mbox_context *context)
+static int init_window_mem(struct mbox_context *context)
{
void *mem_location = context->mem;
int i;
@@ -95,6 +95,60 @@ int init_window_mem(struct mbox_context *context)
return 0;
}
+/*
+ * init_windows() - Initalise the window cache
+ * @context: The mbox context pointer
+ *
+ * Return: 0 on success otherwise negative
+ */
+int init_windows(struct mbox_context *context)
+{
+ int i;
+
+ /* Check if window size and number set - otherwise set to default */
+ if (!context->windows.default_size) {
+ /* Default to 1MB windows */
+ context->windows.default_size = 1 << 20;
+ }
+ MSG_OUT("Window size: 0x%.8x\n", context->windows.default_size);
+ if (!context->windows.num) {
+ /* Use the entire reserved memory region by default */
+ context->windows.num = context->mem_size /
+ context->windows.default_size;
+ }
+ MSG_OUT("Number of Windows: %d\n", context->windows.num);
+
+ context->windows.window = calloc(context->windows.num,
+ sizeof(*context->windows.window));
+ if (!context->windows.window) {
+ MSG_ERR("Memory allocation failed\n");
+ return -1;
+ }
+
+ for (i = 0; i < context->windows.num; i++) {
+ init_window_state(&context->windows.window[i],
+ context->windows.default_size);
+ }
+
+ return init_window_mem(context);
+}
+
+/*
+ * free_windows() - Free the window cache
+ * @context: The mbox context pointer
+ */
+void free_windows(struct mbox_context *context)
+{
+ int i;
+
+ /* Check window cache has actually been allocated */
+ if (context->windows.window) {
+ for (i = 0; i < context->windows.num; i++) {
+ free(context->windows.window[i].dirty_bmap);
+ }
+ free(context->windows.window);
+ }
+}
/* Write from Window Functions */
@@ -310,19 +364,6 @@ void alloc_window_dirty_bytemap(struct mbox_context *context)
}
/*
- * free_window_dirty_bytemap() - free all window dirty bytemaps
- * @context: The mbox context pointer
- */
-void free_window_dirty_bytemap(struct mbox_context *context)
-{
- int i;
-
- for (i = 0; i < context->windows.num; i++) {
- free(context->windows.window[i].dirty_bmap);
- }
-}
-
-/*
* set_window_bytemap() - Set the window bytemap
* @context: The mbox context pointer
* @cur: The window to set the bytemap of
OpenPOWER on IntegriCloud