Browse Source

Merge "msm: camera: utils: Reduce performance impact of printing logs" into camera-kernel.lnx.5.0

Savita Patted 4 years ago
parent
commit
b1f464eec7
3 changed files with 294 additions and 474 deletions
  1. 27 185
      drivers/cam_utils/cam_debug_util.c
  2. 256 281
      drivers/cam_utils/cam_debug_util.h
  3. 11 8
      drivers/cam_utils/cam_trace.h

+ 27 - 185
drivers/cam_utils/cam_debug_util.c

@@ -10,14 +10,14 @@
 
 
 #include "cam_debug_util.h"
 #include "cam_debug_util.h"
 
 
-static unsigned long long debug_mdl;
+unsigned long long debug_mdl;
 module_param(debug_mdl, ullong, 0644);
 module_param(debug_mdl, ullong, 0644);
 
 
 /* 0x0 - only logs, 0x1 - only trace, 0x2 - logs + trace */
 /* 0x0 - only logs, 0x1 - only trace, 0x2 - logs + trace */
-static uint debug_type;
+uint debug_type;
 module_param(debug_type, uint, 0644);
 module_param(debug_type, uint, 0644);
 
 
-static uint debug_priority;
+uint debug_priority;
 module_param(debug_priority, uint, 0644);
 module_param(debug_priority, uint, 0644);
 
 
 struct camera_debug_settings cam_debug;
 struct camera_debug_settings cam_debug;
@@ -123,163 +123,14 @@ error:
 	return -EPERM;
 	return -EPERM;
 }
 }
 
 
-const char *cam_get_module_name(unsigned long long module_id)
-{
-	const char *name = NULL;
-
-	switch (module_id) {
-	case CAM_CDM:
-		name = "CAM-CDM";
-		break;
-	case CAM_CORE:
-		name = "CAM-CORE";
-		break;
-	case CAM_CRM:
-		name = "CAM-CRM";
-		break;
-	case CAM_CPAS:
-		name = "CAM-CPAS";
-		break;
-	case CAM_ISP:
-		name = "CAM-ISP";
-		break;
-	case CAM_SENSOR:
-		name = "CAM-SENSOR";
-		break;
-	case CAM_SMMU:
-		name = "CAM-SMMU";
-		break;
-	case CAM_SYNC:
-		name = "CAM-SYNC";
-		break;
-	case CAM_ICP:
-		name = "CAM-ICP";
-		break;
-	case CAM_JPEG:
-		name = "CAM-JPEG";
-		break;
-	case CAM_FD:
-		name = "CAM-FD";
-		break;
-	case CAM_LRME:
-		name = "CAM-LRME";
-		break;
-	case CAM_FLASH:
-		name = "CAM-FLASH";
-		break;
-	case CAM_ACTUATOR:
-		name = "CAM-ACTUATOR";
-		break;
-	case CAM_CCI:
-		name = "CAM-CCI";
-		break;
-	case CAM_CSIPHY:
-		name = "CAM-CSIPHY";
-		break;
-	case CAM_EEPROM:
-		name = "CAM-EEPROM";
-		break;
-	case CAM_UTIL:
-		name = "CAM-UTIL";
-		break;
-	case CAM_CTXT:
-		name = "CAM-CTXT";
-		break;
-	case CAM_HFI:
-		name = "CAM-HFI";
-		break;
-	case CAM_OIS:
-		name = "CAM-OIS";
-		break;
-	case CAM_IRQ_CTRL:
-		name = "CAM-IRQ-CTRL";
-		break;
-	case CAM_MEM:
-		name = "CAM-MEM";
-		break;
-	case CAM_PERF:
-		name = "CAM-PERF";
-		break;
-	case CAM_REQ:
-		name = "CAM-REQ";
-		break;
-	case CAM_CUSTOM:
-		name = "CAM-CUSTOM";
-		break;
-	case CAM_OPE:
-		name = "CAM-OPE";
-		break;
-	case CAM_PRESIL:
-		name = "CAM-PRESIL";
-		break;
-	case CAM_RES:
-		name = "CAM-RES";
-		break;
-	case CAM_IO_ACCESS:
-		name = "CAM-IO-ACCESS";
-		break;
-	case CAM_SFE:
-		name = "CAM-SFE";
-		break;
-	case CAM_CRE:
-		name = "CAM-CRE";
-		break;
-	case CAM_PRESIL_CORE:
-		name = "CAM-CORE-PRESIL";
-		break;
-	case CAM_TPG:
-		name = "CAM-TPG";
-		break;
-	default:
-		name = "CAM";
-		break;
-	}
-
-	return name;
-}
-
-const char *cam_get_tag_name(unsigned int tag_id)
-{
-	const char *name = NULL;
-
-	switch (tag_id) {
-	case CAM_TYPE_TRACE:
-		name = "CAM_TRACE";
-		break;
-	case CAM_TYPE_ERR:
-		name = "CAM_ERR";
-		break;
-	case CAM_TYPE_WARN:
-		name = "CAM_WARN";
-		break;
-	case CAM_TYPE_INFO:
-		name = "CAM_INFO";
-		break;
-	case CAM_TYPE_DBG:
-		name = "CAM_DBG";
-		break;
-	default:
-		name = "CAM";
-		break;
-	}
-
-	return name;
-}
-
 static inline void __cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len,
 static inline void __cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len,
-	unsigned int tag, unsigned long long module_id, const char *func, const int line,
-	const bool is_final_print, const char *fmt, va_list args)
+	unsigned int tag, enum cam_debug_module_id module_id, const char *fmt, va_list args)
 {
 {
 	size_t buf_len = *len;
 	size_t buf_len = *len;
 
 
-	if (is_final_print)
-		buf_len += scnprintf(buf + buf_len, (buf_size - buf_len), "%s: %s: %s: %d: ",
-			cam_get_tag_name(tag), cam_get_module_name(module_id), func, line);
-	else
-		buf_len += scnprintf(buf + buf_len, (buf_size - buf_len), "\n%-8s: %s:\t",
-			cam_get_tag_name(tag), cam_get_module_name(module_id));
+	buf_len += scnprintf(buf + buf_len, (buf_size - buf_len), "\n%-8s: %s:\t",
+			CAM_LOG_TAG_NAME(tag), CAM_DBG_MOD_NAME(module_id));
 	buf_len += vscnprintf(buf + buf_len, (buf_size - buf_len), fmt, args);
 	buf_len += vscnprintf(buf + buf_len, (buf_size - buf_len), fmt, args);
-
 	*len = buf_len;
 	*len = buf_len;
 }
 }
 
 
@@ -289,43 +140,34 @@ void cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len, unsigned
 	va_list args;
 	va_list args;
 
 
 	va_start(args, fmt);
 	va_start(args, fmt);
-	__cam_print_to_buffer(buf, buf_size, len, tag, module_id, "", 0, false, fmt, args);
+	__cam_print_to_buffer(buf, buf_size, len, tag, module_id, fmt, args);
 	va_end(args);
 	va_end(args);
 }
 }
 
 
-void cam_debug_log(unsigned long long module_id, unsigned int priority,
-	const char *func, const int line, const char *fmt, ...)
+static void __cam_print_log(int type, const char *fmt, va_list args)
 {
 {
-	if ((debug_mdl & module_id) && (priority >= debug_priority)) {
-		char str_buf[STR_BUFFER_MAX_LENGTH];
-		size_t len = 0;
-		va_list args;
-
-		va_start(args, fmt);
-		__cam_print_to_buffer(str_buf, STR_BUFFER_MAX_LENGTH, &len, CAM_TYPE_DBG, module_id,
-			func, line, true, fmt, args);
-
-		if ((debug_type == 0) || (debug_type == 2))
-			pr_info("%s\n", str_buf);
-		if ((debug_type == 1) || (debug_type == 2))
-			trace_cam_log_debug(str_buf);
-
-		va_end(args);
+	va_list args1, args2;
+
+	va_copy(args1, args);
+	va_copy(args2, args1);
+	if ((type & CAM_PRINT_LOG) && (debug_type != 1))
+		vprintk(fmt, args1);
+	if ((type & CAM_PRINT_TRACE) && (debug_type != 0)) {
+		/* skip the first character which is used by printk to identify the log level */
+		trace_cam_log_debug(fmt + sizeof(KERN_INFO) - 1, &args2);
 	}
 	}
+	va_end(args2);
+	va_end(args1);
 }
 }
 
 
-void cam_debug_trace(unsigned int tag, unsigned long long module_id,
-	const char *func, const int line, const char *fmt, ...)
+void cam_print_log(int type, const char *fmt, ...)
 {
 {
-	if ((tag == CAM_TYPE_TRACE) || (debug_type == 1) || (debug_type == 2)) {
-		char str_buf[STR_BUFFER_MAX_LENGTH];
-		size_t len = 0;
-		va_list args;
+	va_list args;
 
 
-		va_start(args, fmt);
-		__cam_print_to_buffer(str_buf, STR_BUFFER_MAX_LENGTH, &len, tag,
-			module_id, func, line, true, fmt, args);
-		trace_cam_log_debug(str_buf);
-		va_end(args);
-	}
+	if (!type)
+		return;
+
+	va_start(args, fmt);
+	__cam_print_log(type, fmt, args);
+	va_end(args);
 }
 }

+ 256 - 281
drivers/cam_utils/cam_debug_util.h

@@ -8,51 +8,60 @@
 
 
 #include <linux/platform_device.h>
 #include <linux/platform_device.h>
 #include "cam_presil_hw_access.h"
 #include "cam_presil_hw_access.h"
+#include "cam_trace.h"
+
+extern unsigned long long debug_mdl;
+extern unsigned int debug_type;
+extern unsigned int debug_priority;
 
 
 /* Module IDs used for debug logging */
 /* Module IDs used for debug logging */
-#define CAM_CDM           BIT_ULL(0)
-#define CAM_CORE          BIT_ULL(1)
-#define CAM_CPAS          BIT_ULL(2)
-#define CAM_ISP           BIT_ULL(3)
-#define CAM_CRM           BIT_ULL(4)
-#define CAM_SENSOR        BIT_ULL(5)
-#define CAM_SMMU          BIT_ULL(6)
-#define CAM_SYNC          BIT_ULL(7)
-#define CAM_ICP           BIT_ULL(8)
-#define CAM_JPEG          BIT_ULL(9)
-#define CAM_FD            BIT_ULL(10)
-#define CAM_LRME          BIT_ULL(11)
-#define CAM_FLASH         BIT_ULL(12)
-#define CAM_ACTUATOR      BIT_ULL(13)
-#define CAM_CCI           BIT_ULL(14)
-#define CAM_CSIPHY        BIT_ULL(15)
-#define CAM_EEPROM        BIT_ULL(16)
-#define CAM_UTIL          BIT_ULL(17)
-#define CAM_HFI           BIT_ULL(18)
-#define CAM_CTXT          BIT_ULL(19)
-#define CAM_OIS           BIT_ULL(20)
-#define CAM_RES           BIT_ULL(21)
-#define CAM_MEM           BIT_ULL(22)
-#define CAM_IRQ_CTRL      BIT_ULL(23)
-#define CAM_REQ           BIT_ULL(24)
-#define CAM_PERF          BIT_ULL(25)
-#define CAM_CUSTOM        BIT_ULL(26)
-#define CAM_PRESIL        BIT_ULL(27)
-#define CAM_OPE           BIT_ULL(28)
-#define CAM_IO_ACCESS     BIT_ULL(29)
-#define CAM_SFE           BIT_ULL(30)
-#define CAM_CRE           BIT_ULL(31)
-#define CAM_PRESIL_CORE   BIT_ULL(32)
-#define CAM_TPG           BIT_ULL(33)
+enum cam_debug_module_id {
+	CAM_CDM,                 /* bit 0 */
+	CAM_CORE,                /* bit 1 */
+	CAM_CPAS,                /* bit 2 */
+	CAM_ISP,                 /* bit 3 */
+	CAM_CRM,                 /* bit 4 */
+	CAM_SENSOR,              /* bit 5 */
+	CAM_SMMU,                /* bit 6 */
+	CAM_SYNC,                /* bit 7 */
+	CAM_ICP,                 /* bit 8 */
+	CAM_JPEG,                /* bit 9 */
+	CAM_FD,                  /* bit 10 */
+	CAM_LRME,                /* bit 11 */
+	CAM_FLASH,               /* bit 12 */
+	CAM_ACTUATOR,            /* bit 13 */
+	CAM_CCI,                 /* bit 14 */
+	CAM_CSIPHY,              /* bit 15 */
+	CAM_EEPROM,              /* bit 16 */
+	CAM_UTIL,                /* bit 17 */
+	CAM_HFI,                 /* bit 18 */
+	CAM_CTXT,                /* bit 19 */
+	CAM_OIS,                 /* bit 20 */
+	CAM_RES,                 /* bit 21 */
+	CAM_MEM,                 /* bit 22 */
+	CAM_IRQ_CTRL,            /* bit 23 */
+	CAM_REQ,                 /* bit 24 */
+	CAM_PERF,                /* bit 25 */
+	CAM_CUSTOM,              /* bit 26 */
+	CAM_PRESIL,              /* bit 27 */
+	CAM_OPE,                 /* bit 28 */
+	CAM_IO_ACCESS,           /* bit 29 */
+	CAM_SFE,                 /* bit 30 */
+	CAM_CRE,                 /* bit 31 */
+	CAM_PRESIL_CORE,         /* bit 32 */
+	CAM_TPG,                 /* bit 33 */
+	CAM_DBG_MOD_MAX
+};
 
 
 /* Log level types */
 /* Log level types */
-#define CAM_TYPE_TRACE      (1 << 0)
-#define CAM_TYPE_ERR        (1 << 1)
-#define CAM_TYPE_WARN       (1 << 2)
-#define CAM_TYPE_INFO       (1 << 3)
-#define CAM_TYPE_DBG        (1 << 4)
-
-#define STR_BUFFER_MAX_LENGTH  512
+enum cam_debug_log_level {
+	CAM_TYPE_TRACE,
+	CAM_TYPE_ERR,
+	CAM_TYPE_WARN,
+	CAM_TYPE_INFO,
+	CAM_TYPE_DBG,
+	CAM_TYPE_MAX,
+};
 
 
 /*
 /*
  * enum cam_debug_priority - Priority of debug log (0 = Lowest)
  * enum cam_debug_priority - Priority of debug log (0 = Lowest)
@@ -63,276 +72,216 @@ enum cam_debug_priority {
 	CAM_DBG_PRIORITY_2,
 	CAM_DBG_PRIORITY_2,
 };
 };
 
 
-/**
- * struct cam_cpas_debug_settings - Sysfs debug settings for cpas driver
- */
-struct cam_cpas_debug_settings {
-	uint64_t mnoc_hf_0_ab_bw;
-	uint64_t mnoc_hf_0_ib_bw;
-	uint64_t mnoc_hf_1_ab_bw;
-	uint64_t mnoc_hf_1_ib_bw;
-	uint64_t mnoc_sf_0_ab_bw;
-	uint64_t mnoc_sf_0_ib_bw;
-	uint64_t mnoc_sf_1_ab_bw;
-	uint64_t mnoc_sf_1_ib_bw;
-	uint64_t mnoc_sf_icp_ab_bw;
-	uint64_t mnoc_sf_icp_ib_bw;
-	uint64_t camnoc_bw;
+static const char *cam_debug_mod_name[CAM_DBG_MOD_MAX] = {
+	[CAM_CDM]         = "CAM-CDM",
+	[CAM_CORE]        = "CAM-CORE",
+	[CAM_CRM]         = "CAM-CRM",
+	[CAM_CPAS]        = "CAM-CPAS",
+	[CAM_ISP]         = "CAM-ISP",
+	[CAM_SENSOR]      = "CAM-SENSOR",
+	[CAM_SMMU]        = "CAM-SMMU",
+	[CAM_SYNC]        = "CAM-SYNC",
+	[CAM_ICP]         = "CAM-ICP",
+	[CAM_JPEG]        = "CAM-JPEG",
+	[CAM_FD]          = "CAM-FD",
+	[CAM_LRME]        = "CAM-LRME",
+	[CAM_FLASH]       = "CAM-FLASH",
+	[CAM_ACTUATOR]    = "CAM-ACTUATOR",
+	[CAM_CCI]         = "CAM-CCI",
+	[CAM_CSIPHY]      = "CAM-CSIPHY",
+	[CAM_EEPROM]      = "CAM-EEPROM",
+	[CAM_UTIL]        = "CAM-UTIL",
+	[CAM_CTXT]        = "CAM-CTXT",
+	[CAM_HFI]         = "CAM-HFI",
+	[CAM_OIS]         = "CAM-OIS",
+	[CAM_IRQ_CTRL]    = "CAM-IRQ-CTRL",
+	[CAM_MEM]         = "CAM-MEM",
+	[CAM_PERF]        = "CAM-PERF",
+	[CAM_REQ]         = "CAM-REQ",
+	[CAM_CUSTOM]      = "CAM-CUSTOM",
+	[CAM_OPE]         = "CAM-OPE",
+	[CAM_PRESIL]      = "CAM-PRESIL",
+	[CAM_RES]         = "CAM-RES",
+	[CAM_IO_ACCESS]   = "CAM-IO-ACCESS",
+	[CAM_SFE]         = "CAM-SFE",
+	[CAM_CRE]         = "CAM-CRE",
+	[CAM_PRESIL_CORE] = "CAM-CORE-PRESIL",
+	[CAM_TPG]         = "CAM-TPG",
 };
 };
 
 
-/**
- * struct camera_debug_settings - Sysfs debug settings for camera
- *
- * @cpas_settings: Debug settings for cpas driver.
- */
-struct camera_debug_settings {
-	struct cam_cpas_debug_settings cpas_settings;
+#define ___CAM_DBG_MOD_NAME(module_id)                                      \
+__builtin_choose_expr(((module_id) == CAM_CDM), "CAM-CDM",                  \
+__builtin_choose_expr(((module_id) == CAM_CORE), "CAM-CORE",                \
+__builtin_choose_expr(((module_id) == CAM_CRM), "CAM-CRM",                  \
+__builtin_choose_expr(((module_id) == CAM_CPAS), "CAM-CPAS",                \
+__builtin_choose_expr(((module_id) == CAM_ISP), "CAM-ISP",                  \
+__builtin_choose_expr(((module_id) == CAM_SENSOR), "CAM-SENSOR",            \
+__builtin_choose_expr(((module_id) == CAM_SMMU), "CAM-SMMU",                \
+__builtin_choose_expr(((module_id) == CAM_SYNC), "CAM-SYNC",                \
+__builtin_choose_expr(((module_id) == CAM_ICP), "CAM-ICP",                  \
+__builtin_choose_expr(((module_id) == CAM_JPEG), "CAM-JPEG",                \
+__builtin_choose_expr(((module_id) == CAM_FD), "CAM-FD",                    \
+__builtin_choose_expr(((module_id) == CAM_LRME), "CAM-LRME",                \
+__builtin_choose_expr(((module_id) == CAM_FLASH), "CAM-FLASH",              \
+__builtin_choose_expr(((module_id) == CAM_ACTUATOR), "CAM-ACTUATOR",        \
+__builtin_choose_expr(((module_id) == CAM_CCI), "CAM-CCI",                  \
+__builtin_choose_expr(((module_id) == CAM_CSIPHY), "CAM-CSIPHY",            \
+__builtin_choose_expr(((module_id) == CAM_EEPROM), "CAM-EEPROM",            \
+__builtin_choose_expr(((module_id) == CAM_UTIL), "CAM-UTIL",                \
+__builtin_choose_expr(((module_id) == CAM_CTXT), "CAM-CTXT",                \
+__builtin_choose_expr(((module_id) == CAM_HFI), "CAM-HFI",                  \
+__builtin_choose_expr(((module_id) == CAM_OIS), "CAM-OIS",                  \
+__builtin_choose_expr(((module_id) == CAM_IRQ_CTRL), "CAM-IRQ-CTRL",        \
+__builtin_choose_expr(((module_id) == CAM_MEM), "CAM-MEM",                  \
+__builtin_choose_expr(((module_id) == CAM_PERF), "CAM-PERF",                \
+__builtin_choose_expr(((module_id) == CAM_REQ), "CAM-REQ",                  \
+__builtin_choose_expr(((module_id) == CAM_CUSTOM), "CAM-CUSTOM",            \
+__builtin_choose_expr(((module_id) == CAM_OPE), "CAM-OPE",                  \
+__builtin_choose_expr(((module_id) == CAM_PRESIL), "CAM-PRESIL",            \
+__builtin_choose_expr(((module_id) == CAM_RES), "CAM-RES",                  \
+__builtin_choose_expr(((module_id) == CAM_IO_ACCESS), "CAM-IO-ACCESS",      \
+__builtin_choose_expr(((module_id) == CAM_SFE), "CAM-SFE",                  \
+__builtin_choose_expr(((module_id) == CAM_CRE), "CAM-CRE",                  \
+__builtin_choose_expr(((module_id) == CAM_PRESIL_CORE), "CAM-CORE-PRESIL",  \
+__builtin_choose_expr(((module_id) == CAM_TPG), "CAM-TPG",                  \
+"CAMERA"))))))))))))))))))))))))))))))))))
+
+#define CAM_DBG_MOD_NAME(module_id) \
+((module_id < CAM_DBG_MOD_MAX) ? cam_debug_mod_name[module_id] : "CAMERA")
+
+#define __CAM_DBG_MOD_NAME(module_id) \
+__builtin_choose_expr(__builtin_constant_p((module_id)), ___CAM_DBG_MOD_NAME(module_id), \
+	CAM_DBG_MOD_NAME(module_id))
+
+static const char *cam_debug_tag_name[CAM_TYPE_MAX] = {
+	[CAM_TYPE_TRACE] = "CAM_TRACE",
+	[CAM_TYPE_ERR]   = "CAM_ERR",
+	[CAM_TYPE_WARN]  = "CAM_WARN",
+	[CAM_TYPE_INFO]  = "CAM_INFO",
+	[CAM_TYPE_DBG]   = "CAM_DBG",
 };
 };
 
 
-/*
- *  cam_debug_log()
- *
- * @brief     :  Get the Module name from module ID and print
- *               respective debug logs
- *
- * @module_id :  Respective Module ID which is calling this function
- * @priority  :  Priority of the debug log
- * @func      :  Function which is calling to print logs
- * @line      :  Line number associated with the function which is calling
- *               to print log
- * @fmt       :  Formatted string which needs to be print in the log
- *
- */
-void cam_debug_log(unsigned long long module_id, unsigned int priority,
-	const char *func, const int line, const char *fmt, ...);
+#define ___CAM_LOG_TAG_NAME(tag)                     \
+({                                                  \
+	static_assert(tag < CAM_TYPE_MAX);          \
+	cam_debug_tag_name[tag];                    \
+})
 
 
-/*
- *  cam_debug_trace()
- *
- * @brief     :  Get the Module name from module ID and print
- *               respective debug logs in ftrace
- *
- * @tag       :  Tag indicating whether TRACE, ERR, WARN, INFO, DBG
- * @module_id :  Respective Module ID which is calling this function
- * @func      :  Function which is calling to print logs
- * @line      :  Line number associated with the function which is calling
- *               to print log
- * @fmt       :  Formatted string which needs to be print in the log
- *
- */
-void cam_debug_trace(unsigned int tag, unsigned long long module_id,
-	const char *func, const int line, const char *fmt, ...);
+#define CAM_LOG_TAG_NAME(tag) ((tag < CAM_TYPE_MAX) ? cam_debug_tag_name[tag] : "CAM_LOG")
 
 
-/*
- * cam_get_module_name()
- *
- * @brief     :  Get the module name from module ID
- *
- * @module_id :  Module ID which is using this function
- */
-const char *cam_get_module_name(unsigned long long module_id);
+#define __CAM_LOG_TAG_NAME(tag) \
+__builtin_choose_expr(__builtin_constant_p((tag)), ___CAM_LOG_TAG_NAME(tag), \
+	CAM_LOG_TAG_NAME(tag))
 
 
-/*
- * CAM_TRACE
- * @brief    :  This Macro will print logs in ftrace
- *
- * @__module :  Respective module id which is been calling this Macro
- * @fmt      :  Formatted string which needs to be print in log
- * @args     :  Arguments which needs to be print in log
- */
-#define CAM_TRACE(__module, fmt, args...)                                      \
-	({                                                                     \
-		cam_debug_trace(CAM_TYPE_TRACE, __module, __func__, __LINE__,  \
-			fmt, ##args);                                          \
-	})
+enum cam_log_print_type {
+	CAM_PRINT_LOG   = 0x1,
+	CAM_PRINT_TRACE = 0x2,
+	CAM_PRINT_BOTH  = 0x3,
+};
 
 
-/*
- * CAM_ERR
- * @brief    :  This Macro will print error logs
- *
- * @__module :  Respective module id which is been calling this Macro
- * @fmt      :  Formatted string which needs to be print in log
- * @args     :  Arguments which needs to be print in log
- */
-#define CAM_ERR(__module, fmt, args...)                                        \
-	({                                                                     \
-		pr_info("CAM_ERR: %s: %s: %d " fmt "\n",                       \
-			cam_get_module_name(__module), __func__,               \
-			__LINE__, ##args);                                     \
-		cam_debug_trace(CAM_TYPE_ERR, __module, __func__, __LINE__,    \
-			fmt, ##args);                                          \
-	})
+#define __CAM_LOG_FMT KERN_INFO "%s: %s: %s: %d "
 
 
-/*
- * CAM_WARN
- * @brief    :  This Macro will print warning logs
+/**
+ * cam_print_log() - function to print logs (internal use only, use macros instead)
  *
  *
- * @__module :  Respective module id which is been calling this Macro
- * @fmt      :  Formatted string which needs to be print in log
- * @args     :  Arguments which needs to be print in log
+ * @type: corresponds to enum cam_log_print_type, selects if logs are printed in log buffer,
+ *        trace buffers or both
+ * @fmt:  formatting string
+ * @args: arguments corresponding to formatting string
  */
  */
-#define CAM_WARN(__module, fmt, args...)                                       \
-	({                                                                     \
-		pr_info("CAM_WARN: %s: %s: %d " fmt "\n",                      \
-			cam_get_module_name(__module), __func__,               \
-			__LINE__, ##args);                                     \
-		cam_debug_trace(CAM_TYPE_ERR, __module, __func__, __LINE__,    \
-			fmt, ##args);                                          \
-	})
 
 
-/*
- * CAM_INFO
- * @brief    :  This Macro will print Information logs
- *
- * @__module :  Respective module id which is been calling this Macro
- * @fmt      :  Formatted string which needs to be print in log
- * @args     :  Arguments which needs to be print in log
- */
-#define CAM_INFO(__module, fmt, args...)                                       \
-	({                                                                     \
-		pr_info("CAM_INFO: %s: %s: %d " fmt "\n",                      \
-			cam_get_module_name(__module), __func__,               \
-			__LINE__, ##args);                                     \
-		cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__,   \
-			fmt, ##args);                                          \
-	})
+void cam_print_log(int type, const char *fmt, ...);
 
 
-/*
- * CAM_INFO_RATE_LIMIT
- * @brief    :  This Macro will print info logs with ratelimit
- *
- * @__module :  Respective module id which is been calling this Macro
- * @fmt      :  Formatted string which needs to be print in log
- * @args     :  Arguments which needs to be print in log
- */
-#define CAM_INFO_RATE_LIMIT(__module, fmt, args...)                            \
-	({                                                                     \
-		pr_info_ratelimited("CAM_INFO: %s: %s: %d " fmt "\n",          \
-			cam_get_module_name(__module), __func__,               \
-			__LINE__, ##args);                                     \
-		cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__,   \
-			fmt, ##args);                                          \
-	})
+#define __CAM_LOG(type, tag, module_id, fmt, args...)                               \
+({                                                                                  \
+	cam_print_log(type, __CAM_LOG_FMT fmt,                                      \
+		__CAM_LOG_TAG_NAME(tag), __CAM_DBG_MOD_NAME(module_id), __func__,   \
+		__LINE__, ##args);                                                  \
+})
 
 
-/*
- * CAM_DBG
- * @brief    :  This Macro will print debug logs when enabled using GROUP and
- *              if its priority is greater than the priority parameter
- *
- * @__module :  Respective module id which is been calling this Macro
- * @fmt      :  Formatted string which needs to be print in log
- * @args     :  Arguments which needs to be print in log
- */
-#define CAM_DBG(__module, fmt, args...)                                        \
-	cam_debug_log(__module, CAM_DBG_PRIORITY_0, __func__, __LINE__,        \
-			fmt, ##args)
-#define CAM_DBG_PR1(__module, fmt, args...)                                    \
-	cam_debug_log(__module, CAM_DBG_PRIORITY_1, __func__, __LINE__,        \
-			fmt, ##args)
-#define CAM_DBG_PR2(__module, fmt, args...)                                    \
-	cam_debug_log(__module, CAM_DBG_PRIORITY_2, __func__, __LINE__,        \
-			fmt, ##args)
+#define CAM_LOG(tag, module_id, fmt, args...) \
+__CAM_LOG(CAM_PRINT_BOTH, tag, module_id, fmt, ##args)
 
 
-/*
- * CAM_ERR_RATE_LIMIT
- * @brief    :  This Macro will print error print logs with ratelimit
- */
-#define CAM_ERR_RATE_LIMIT(__module, fmt, args...)                             \
-	({                                                                     \
-		pr_info_ratelimited("CAM_ERR: %s: %s: %d " fmt "\n",           \
-			cam_get_module_name(__module), __func__,               \
-			__LINE__, ##args);                                     \
-		cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__,   \
-			fmt, ##args);                                          \
-	})
-/*
- * CAM_WARN_RATE_LIMIT
- * @brief    :  This Macro will print warning logs with ratelimit
+#define CAM_LOG_RL_CUSTOM(type, module_id, interval, burst, fmt, args...)                \
+({                                                                                       \
+	static DEFINE_RATELIMIT_STATE(_rs, (interval * HZ), burst);                      \
+	__CAM_LOG(__ratelimit(&_rs) ? CAM_PRINT_BOTH : CAM_PRINT_TRACE,                  \
+		type, module_id, fmt, ##args);                                           \
+})
+
+#define CAM_LOG_RL(type, module_id, fmt, args...)                                        \
+CAM_LOG_RL_CUSTOM(type, module_id, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST,  \
+fmt, ##args)
+
+#define __CAM_DBG(module_id, priority, fmt, args...)                                              \
+({                                                                                                \
+	if (unlikely((debug_mdl & BIT_ULL(module_id)) && (priority >= debug_priority))) {         \
+		CAM_LOG(CAM_TYPE_DBG, module_id, fmt, ##args);                                    \
+	}                                                                                         \
+})
+
+/**
+ * CAM_ERR / CAM_WARN / CAM_INFO / CAM_TRACE
  *
  *
- * @__module :  Respective module id which is been calling this Macro
- * @fmt      :  Formatted string which needs to be print in log
- * @args     :  Arguments which needs to be print in log
+ * @brief: Macros to print logs at respective level error/warn/info/trace. All
+ * logs except CAM_TRACE are printed in both log and trace buffers.
+ *
+ * @__module: Respective enum cam_debug_module_id
+ * @fmt:      Format string
+ * @args:     Arguments to match with format
  */
  */
-#define CAM_WARN_RATE_LIMIT(__module, fmt, args...)                            \
-	({                                                                     \
-		pr_info_ratelimited("CAM_WARN: %s: %s: %d " fmt "\n",          \
-			cam_get_module_name(__module), __func__,               \
-			__LINE__, ##args);                                     \
-		cam_debug_trace(CAM_TYPE_WARN, __module, __func__, __LINE__,   \
-			fmt, ##args);                                          \
-	})
+#define CAM_ERR(__module, fmt, args...)  CAM_LOG(CAM_TYPE_ERR, __module, fmt, ##args)
+#define CAM_WARN(__module, fmt, args...) CAM_LOG(CAM_TYPE_WARN, __module, fmt, ##args)
+#define CAM_INFO(__module, fmt, args...) CAM_LOG(CAM_TYPE_INFO, __module, fmt, ##args)
+#define CAM_TRACE(__module, fmt, args...) \
+__CAM_LOG(CAM_PRINT_TRACE, CAM_TYPE_TRACE, __module, fmt, ##args)
 
 
-/*
- * CAM_WARN_RATE_LIMIT_CUSTOM
- * @brief    :  This Macro will print warn logs with custom ratelimit
+/**
+ * CAM_ERR_RATE_LIMIT / CAM_WARN_RATE_LIMIT / CAM_INFO_RATE_LIMIT
  *
  *
- * @__module :  Respective module id which is been calling this Macro
- * @interval :  Time interval in seconds
- * @burst    :  No of logs to print in interval time
- * @fmt      :  Formatted string which needs to be print in log
- * @args     :  Arguments which needs to be print in log
+ * @brief: Rate limited version of logs used to reduce log spew.
+ *
+ * @__module: Respective enum cam_debug_module_id
+ * @fmt:      Format string
+ * @args:     Arguments to match with format
  */
  */
-#define CAM_WARN_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...)    \
-	({                                                                     \
-		static DEFINE_RATELIMIT_STATE(_rs,                             \
-			(interval * HZ),                                       \
-			burst);                                                \
-		if (__ratelimit(&_rs))                                         \
-			pr_info(                                               \
-				"CAM_WARN: %s: %s: %d " fmt "\n",              \
-				cam_get_module_name(__module), __func__,       \
-				__LINE__, ##args);                             \
-		cam_debug_trace(CAM_TYPE_WARN, __module, __func__, __LINE__,   \
-			fmt, ##args);                                          \
-	})
+#define CAM_ERR_RATE_LIMIT(__module, fmt, args...)  CAM_LOG_RL(CAM_TYPE_ERR, __module, fmt, ##args)
+#define CAM_WARN_RATE_LIMIT(__module, fmt, args...) CAM_LOG_RL(CAM_TYPE_WARN, __module, fmt, ##args)
+#define CAM_INFO_RATE_LIMIT(__module, fmt, args...) CAM_LOG_RL(CAM_TYPE_INFO, __module, fmt, ##args)
 
 
-/*
- * CAM_INFO_RATE_LIMIT_CUSTOM
- * @brief    :  This Macro will print info logs with custom ratelimit
+/**
+ * CAM_ERR_RATE_LIMIT_CUSTOM / CAM_WARN_RATE_LIMITT_CUSTOM/ CAM_INFO_RATE_LIMITT_CUSTOM
  *
  *
- * @__module :  Respective module id which is been calling this Macro
- * @interval :  Time interval in seconds
- * @burst    :  No of logs to print in interval time
- * @fmt      :  Formatted string which needs to be print in log
- * @args     :  Arguments which needs to be print in log
+ * @brief: Rate limited version of logs used to reduce log spew that can have
+ * customized burst rate
+ *
+ * @__module: Respective enum cam_debug_module_id
+ * @interval: Sliding window interval in which to count logs
+ * @burst:    Maximum number of logs in the specified interval
+ * @fmt:      Format string
+ * @args:     Arguments to match with format
  */
  */
-#define CAM_INFO_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...)    \
-	({                                                                     \
-		static DEFINE_RATELIMIT_STATE(_rs,                             \
-			(interval * HZ),                                       \
-			burst);                                                \
-		if (__ratelimit(&_rs))                                         \
-			pr_info(                                               \
-				"CAM_INFO: %s: %s: %d " fmt "\n",              \
-				cam_get_module_name(__module), __func__,       \
-				__LINE__, ##args);                             \
-		cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__,   \
-			fmt, ##args);                                          \
-	})
+#define CAM_ERR_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...)  \
+	CAM_LOG_RL_CUSTOM(CAM_TYPE_ERR, __module, interval, burst, fmt, ##args)
+
+#define CAM_WARN_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
+	CAM_LOG_RL_CUSTOM(CAM_TYPE_WARN, __module, interval, burst, fmt, ##args)
+
+#define CAM_INFO_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
+	CAM_LOG_RL_CUSTOM(CAM_TYPE_INFO, __module, interval, burst, fmt, ##args)
 
 
 /*
 /*
- * CAM_ERR_RATE_LIMIT_CUSTOM
- * @brief    :  This Macro will print error logs with custom ratelimit
+ * CAM_DBG
+ * @brief    :  This Macro will print debug logs when enabled using GROUP and
+ *              if its priority is greater than the priority parameter
  *
  *
  * @__module :  Respective module id which is been calling this Macro
  * @__module :  Respective module id which is been calling this Macro
- * @interval :  Time interval in seconds
- * @burst    :  No of logs to print in interval time
  * @fmt      :  Formatted string which needs to be print in log
  * @fmt      :  Formatted string which needs to be print in log
  * @args     :  Arguments which needs to be print in log
  * @args     :  Arguments which needs to be print in log
  */
  */
-#define CAM_ERR_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...)    \
-	({                                                                    \
-		static DEFINE_RATELIMIT_STATE(_rs,                            \
-			(interval * HZ),                                      \
-			burst);                                               \
-		if (__ratelimit(&_rs))                                        \
-			pr_info(                                              \
-				"CAM_ERR: %s: %s: %d " fmt "\n",              \
-				cam_get_module_name(__module), __func__,      \
-				__LINE__, ##args);                            \
-		cam_debug_trace(CAM_TYPE_ERR, __module, __func__, __LINE__,   \
-			fmt, ##args);                                         \
-	})
+#define CAM_DBG(__module, fmt, args...)     __CAM_DBG(__module, CAM_DBG_PRIORITY_0, fmt, ##args)
+#define CAM_DBG_PR1(__module, fmt, args...) __CAM_DBG(__module, CAM_DBG_PRIORITY_1, fmt, ##args)
+#define CAM_DBG_PR2(__module, fmt, args...) __CAM_DBG(__module, CAM_DBG_PRIORITY_2, fmt, ##args)
 
 
 /**
 /**
  * cam_print_to_buffer
  * cam_print_to_buffer
@@ -368,6 +317,32 @@ void cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len, unsigned
 #define CAM_INFO_BUF(module_id, buf, buf_size, len, fmt, args...)                                  \
 #define CAM_INFO_BUF(module_id, buf, buf_size, len, fmt, args...)                                  \
 	cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_INFO, module_id, fmt, ##args)
 	cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_INFO, module_id, fmt, ##args)
 
 
+/**
+ * struct cam_cpas_debug_settings - Sysfs debug settings for cpas driver
+ */
+struct cam_cpas_debug_settings {
+	uint64_t mnoc_hf_0_ab_bw;
+	uint64_t mnoc_hf_0_ib_bw;
+	uint64_t mnoc_hf_1_ab_bw;
+	uint64_t mnoc_hf_1_ib_bw;
+	uint64_t mnoc_sf_0_ab_bw;
+	uint64_t mnoc_sf_0_ib_bw;
+	uint64_t mnoc_sf_1_ab_bw;
+	uint64_t mnoc_sf_1_ib_bw;
+	uint64_t mnoc_sf_icp_ab_bw;
+	uint64_t mnoc_sf_icp_ib_bw;
+	uint64_t camnoc_bw;
+};
+
+/**
+ * struct camera_debug_settings - Sysfs debug settings for camera
+ *
+ * @cpas_settings: Debug settings for cpas driver.
+ */
+struct camera_debug_settings {
+	struct cam_cpas_debug_settings cpas_settings;
+};
+
 /**
 /**
  * @brief : API to get camera debug settings
  * @brief : API to get camera debug settings
  * @return const struct camera_debug_settings pointer.
  * @return const struct camera_debug_settings pointer.

+ 11 - 8
drivers/cam_utils/cam_trace.h

@@ -20,6 +20,7 @@
 #include "cam_context.h"
 #include "cam_context.h"
 
 
 #define CAM_DEFAULT_VALUE 0xFF
 #define CAM_DEFAULT_VALUE 0xFF
+#define CAM_TRACE_PRINT_MAX_LEN 512
 
 
 TRACE_EVENT(cam_context_state,
 TRACE_EVENT(cam_context_state,
 	TP_PROTO(const char *name, struct cam_context *ctx),
 	TP_PROTO(const char *name, struct cam_context *ctx),
@@ -92,20 +93,22 @@ TRACE_EVENT(cam_log_event,
 );
 );
 
 
 TRACE_EVENT(cam_log_debug,
 TRACE_EVENT(cam_log_debug,
-	TP_PROTO(const char *string1),
-	TP_ARGS(string1),
+	TP_PROTO(const char *fmt, va_list *args),
+	TP_ARGS(fmt, args),
 	TP_STRUCT__entry(
 	TP_STRUCT__entry(
-		__string(string1, string1)
+		__dynamic_array(char, msg, CAM_TRACE_PRINT_MAX_LEN)
 	),
 	),
 	TP_fast_assign(
 	TP_fast_assign(
-		__assign_str(string1, string1);
+		va_list ap;
+
+		va_copy(ap, *args);
+		vsnprintf(__get_dynamic_array(msg), CAM_TRACE_PRINT_MAX_LEN, fmt, ap);
+		va_end(ap);
 	),
 	),
-	TP_printk(
-		"%s",
-		__get_str(string1)
-	)
+	TP_printk("%s", __get_str(msg))
 );
 );
 
 
+
 TRACE_EVENT(cam_icp_fw_dbg,
 TRACE_EVENT(cam_icp_fw_dbg,
 	TP_PROTO(char *dbg_message, uint64_t timestamp),
 	TP_PROTO(char *dbg_message, uint64_t timestamp),
 	TP_ARGS(dbg_message, timestamp),
 	TP_ARGS(dbg_message, timestamp),