[qca-nss-drv] Use BUILD_BUG_ON and change nss_freq_sched_change
Fixed the following issues:
- Used BUILD_BUG_ON macro provided by Linux kernel to perform
compile time structure size checks.
- Changed the return type of nss_freq_sched_change() to bool
so that the freq_scale_index counter can be updated accordingly
Change-Id: I075e8bd4d57576c9d8bf70c930c96a8e3a345a63
Signed-off-by: Tanmay V Jagdale <tjagdale@codeaurora.org>
diff --git a/nss_freq.c b/nss_freq.c
index ce04bfb..86adbb6 100644
--- a/nss_freq.c
+++ b/nss_freq.c
@@ -1,6 +1,6 @@
/*
**************************************************************************
- * Copyright (c) 2013, 2015-2016 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013, 2015-2017 The Linux Foundation. All rights reserved.
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all copies.
@@ -70,7 +70,7 @@
* nss_freq_queue_work()
* Queue Work to the NSS Workqueue based on Current index.
*/
-static int nss_freq_queue_work(void)
+static bool nss_freq_queue_work(void)
{
nss_freq_scales_t index = nss_runtime_samples.freq_scale_index;
@@ -82,9 +82,7 @@
/*
* schedule freq change with autoscale ON
*/
- nss_freq_sched_change(index, true);
-
- return 0;
+ return nss_freq_sched_change(index, true);
}
/*
@@ -170,7 +168,7 @@
* If fail to increase frequency, decrease index
*/
nss_trace("frequency increase to %d inst:%x > maximum:%x\n", nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency, sample, maximum);
- if (nss_freq_queue_work()) {
+ if (!nss_freq_queue_work()) {
nss_runtime_samples.freq_scale_index--;
}
}
@@ -197,7 +195,7 @@
* If fail to decrease frequency, increase index
*/
nss_trace("frequency decrease to %d inst:%x < minumum:%x\n", nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency, nss_runtime_samples.average, minimum);
- if (nss_freq_queue_work()) {
+ if (!nss_freq_queue_work()) {
nss_runtime_samples.freq_scale_index++;
}
}
@@ -281,17 +279,17 @@
* nss_freq_sched_change()
* schedule a frequency work
*/
-void nss_freq_sched_change(nss_freq_scales_t index, bool auto_scale)
+bool nss_freq_sched_change(nss_freq_scales_t index, bool auto_scale)
{
if (index >= NSS_FREQ_MAX_SCALE) {
nss_info("NSS freq scale beyond limit\n");
- return;
+ return false;
}
nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_ATOMIC);
if (!nss_work) {
nss_info("NSS Freq WQ kmalloc fail");
- return;
+ return false;
}
INIT_WORK((struct work_struct *)nss_work, nss_wq_function);
@@ -301,6 +299,8 @@
nss_work->stats_enable = auto_scale;
nss_cmd_buf.current_freq = nss_work->frequency;
queue_work(nss_wq, (struct work_struct *)nss_work);
+
+ return true;
}
/*