From 205e26e4e52237610789178c872723b024de2df5 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 5 Jul 2022 06:51:41 +0900 Subject: [PATCH] util: resource: Discard const keyword of struct resource Discard const keyword when accessing struct resource by hiding the 'struct resource' from use of 'struct resource'. Except for 'void *priv' field of struct resource, the fields of struct resource should be accessed by getter/setter functions. Change-Id: I80fe2a7c9df8f6a5c273da9f222668a03ba8e62e Signed-off-by: Chanwoo Choi --- include/util/resource.h | 14 +++++++------- src/resource/resource-battery.c | 4 ++-- src/resource/resource-bus.c | 6 +++--- src/resource/resource-cpu.c | 6 +++--- src/resource/resource-display.c | 4 ++-- src/resource/resource-gpu.c | 6 +++--- src/resource/resource-memory.c | 2 +- src/resource/resource-process-group.c | 14 +++++++------- src/resource/resource-process.c | 12 ++++++------ src/resource/resource-system.c | 6 +++--- src/util/resource.c | 2 +- 11 files changed, 38 insertions(+), 38 deletions(-) diff --git a/include/util/resource.h b/include/util/resource.h index d9b62f7..e96d3ba 100644 --- a/include/util/resource.h +++ b/include/util/resource.h @@ -40,17 +40,17 @@ struct resource_attribute_value { }; struct resource_attribute_ops { - int (*set)(const struct resource *res, + int (*set)(struct resource *res, const struct resource_attribute *attr, const void *data, int count); - int (*get)(const struct resource *res, + int (*get)(struct resource *res, const struct resource_attribute *attr, void *data); /* * If .is_supported ops is not implemented, use .get ops in order to * check whether the resource attribute is supported or not. */ - bool (*is_supported)(const struct resource *res, + bool (*is_supported)(struct resource *res, const struct resource_attribute *attr); }; @@ -64,10 +64,10 @@ struct resource_attribute { struct resource_control; struct resource_control_ops { - const int (*set)(const struct resource *res, + const int (*set)(struct resource *res, const struct resource_control *ctrl, const void *data); - const int (*get)(const struct resource *res, + const int (*get)(struct resource *res, const struct resource_control *ctrl, void **data); }; @@ -144,7 +144,7 @@ get_resource_attr_value(struct resource *resource, u_int64_t attr_id); bool is_resource_attr_supported(struct resource *resource, u_int64_t attr_id); static inline bool -resource_attr_supported_always(const struct resource *resource, +resource_attr_supported_always(struct resource *resource, const struct resource_attribute *attr) { return true; @@ -166,7 +166,7 @@ int get_resource_attr_ptr(struct resource *resource, u_int64_t attr_id, void **d int set_resource_attr_interest(struct resource *resource, u_int64_t interest_mask); int unset_resource_attr_interest(struct resource *resource, u_int64_t interest_mask); -bool is_resource_attr_interested(const struct resource *resource, u_int64_t interest_mask); +bool is_resource_attr_interested(struct resource *resource, u_int64_t interest_mask); const char *get_resource_name(struct resource *resource); void *get_resource_privdata(struct resource *resource); diff --git a/src/resource/resource-battery.c b/src/resource/resource-battery.c index 584fe2f..ed51d39 100644 --- a/src/resource/resource-battery.c +++ b/src/resource/resource-battery.c @@ -30,7 +30,7 @@ #include -static int battery_get_info(const struct resource *res, +static int battery_get_info(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -71,7 +71,7 @@ static int battery_get_info(const struct resource *res, return 0; } -static int battery_get_status(const struct resource *res, +static int battery_get_status(struct resource *res, const struct resource_attribute *attr, void *data) { diff --git a/src/resource/resource-bus.c b/src/resource/resource-bus.c index a1f2a9a..7366111 100644 --- a/src/resource/resource-bus.c +++ b/src/resource/resource-bus.c @@ -37,7 +37,7 @@ struct bus_context { int index; }; -static int bus_get_value_from_hal_power(const struct resource *res, +static int bus_get_value_from_hal_power(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -89,7 +89,7 @@ static int bus_get_value_from_hal_power(const struct resource *res, return 0; } -static int bus_get_curr_governor(const struct resource *res, +static int bus_get_curr_governor(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -164,7 +164,7 @@ static const struct resource_attribute bus_attrs[] = { }, }; -static int bus_setup_device_id(const struct resource *res, +static int bus_setup_device_id(struct resource *res, const struct resource_control *ctrl, const void *data) { diff --git a/src/resource/resource-cpu.c b/src/resource/resource-cpu.c index 1651e30..4613705 100644 --- a/src/resource/resource-cpu.c +++ b/src/resource/resource-cpu.c @@ -37,7 +37,7 @@ struct cpu_context { int index; }; -static int cpu_get_value_from_hal_power(const struct resource *res, +static int cpu_get_value_from_hal_power(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -88,7 +88,7 @@ static int cpu_get_value_from_hal_power(const struct resource *res, return 0; } -static int cpu_get_curr_governor(const struct resource *res, +static int cpu_get_curr_governor(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -163,7 +163,7 @@ static const struct resource_attribute cpu_attrs[] = { }, }; -static int cpu_setup_cluster_id(const struct resource *res, +static int cpu_setup_cluster_id(struct resource *res, const struct resource_control *ctrl, const void *data) { diff --git a/src/resource/resource-display.c b/src/resource/resource-display.c index ea05b32..7cfebdb 100644 --- a/src/resource/resource-display.c +++ b/src/resource/resource-display.c @@ -46,7 +46,7 @@ struct display_fps_data { double fps; }; -static int display_get_fps(const struct resource *res, +static int display_get_fps(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -139,7 +139,7 @@ static const struct resource_attribute display_attrs[] = { }, }; -static int display_setup_device_id(const struct resource *res, +static int display_setup_device_id(struct resource *res, const struct resource_control *ctrl, const void *data) { diff --git a/src/resource/resource-gpu.c b/src/resource/resource-gpu.c index c9cc0b3..4fdce6c 100644 --- a/src/resource/resource-gpu.c +++ b/src/resource/resource-gpu.c @@ -37,7 +37,7 @@ struct gpu_context { int index; }; -static int gpu_get_value_from_hal_power(const struct resource *res, +static int gpu_get_value_from_hal_power(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -89,7 +89,7 @@ static int gpu_get_value_from_hal_power(const struct resource *res, return 0; } -static int gpu_get_curr_governor(const struct resource *res, +static int gpu_get_curr_governor(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -164,7 +164,7 @@ static const struct resource_attribute gpu_attrs[] = { }, }; -static int gpu_setup_device_id(const struct resource *res, +static int gpu_setup_device_id(struct resource *res, const struct resource_control *ctrl, const void *data) { diff --git a/src/resource/resource-memory.c b/src/resource/resource-memory.c index 48c627d..a9218d2 100644 --- a/src/resource/resource-memory.c +++ b/src/resource/resource-memory.c @@ -76,7 +76,7 @@ static int memory_get_swap_total(u_int64_t *val) return 0; } -static int memory_get_memory_info(const struct resource *res, +static int memory_get_memory_info(struct resource *res, const struct resource_attribute *attr, void *data) { diff --git a/src/resource/resource-process-group.c b/src/resource/resource-process-group.c index 5d056ed..e6a2812 100644 --- a/src/resource/resource-process-group.c +++ b/src/resource/resource-process-group.c @@ -52,7 +52,7 @@ struct process_group_context { static u_int64_t total_memory; static long jiffy; -static int process_group_get_pid_list(const struct resource *res, +static int process_group_get_pid_list(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -92,7 +92,7 @@ static int process_group_get_pid_list(const struct resource *res, return 0; } -static int process_group_get_comm_list(const struct resource *res, +static int process_group_get_comm_list(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -145,7 +145,7 @@ static int process_group_get_comm_list(const struct resource *res, return 0; } -static int process_group_get_cpu_util(const struct resource *res, +static int process_group_get_cpu_util(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -167,7 +167,7 @@ static int process_group_get_cpu_util(const struct resource *res, return 0; } -static int process_group_get_mem(const struct resource *res, +static int process_group_get_mem(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -210,7 +210,7 @@ static int process_group_get_mem(const struct resource *res, return 0; } -static int process_group_get_disk_bps(const struct resource *res, +static int process_group_get_disk_bps(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -240,7 +240,7 @@ static int process_group_get_disk_bps(const struct resource *res, return 0; } -static bool process_group_check_gpu_support(const struct resource *resource, +static bool process_group_check_gpu_support(struct resource *resource, const struct resource_attribute *attr) { return kernel_check_gpu_support(); @@ -338,7 +338,7 @@ static const struct resource_attribute process_group_attrs[] = { }, }; -static int process_group_setup_root_pid(const struct resource *res, +static int process_group_setup_root_pid(struct resource *res, const struct resource_control *ctrl, const void *data) { diff --git a/src/resource/resource-process.c b/src/resource/resource-process.c index 5d99b3e..600d3d9 100644 --- a/src/resource/resource-process.c +++ b/src/resource/resource-process.c @@ -42,7 +42,7 @@ struct process_context { static long jiffy; -static int process_get_cpu_util(const struct resource *res, +static int process_get_cpu_util(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -76,7 +76,7 @@ static int process_get_cpu_util(const struct resource *res, return 0; } -static int process_get_mem_attrs(const struct resource *res, +static int process_get_mem_attrs(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -134,7 +134,7 @@ static int process_get_mem_attrs(const struct resource *res, return 0; } -static int process_get_disk_bps(const struct resource *res, +static int process_get_disk_bps(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -174,7 +174,7 @@ static int process_get_disk_bps(const struct resource *res, return 0; } -static int process_get_context_data(const struct resource *res, +static int process_get_context_data(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -221,7 +221,7 @@ static int process_get_context_data(const struct resource *res, return 0; } -static bool process_check_gpu_support(const struct resource *resource, +static bool process_check_gpu_support(struct resource *resource, const struct resource_attribute *attr) { return kernel_check_gpu_support(); @@ -355,7 +355,7 @@ static u_int64_t get_total_cpu_time(void) return total_time; } -static int process_setup_tgid(const struct resource *res, +static int process_setup_tgid(struct resource *res, const struct resource_control *ctrl, const void *data) { diff --git a/src/resource/resource-system.c b/src/resource/resource-system.c index 99a22f6..72d5835 100644 --- a/src/resource/resource-system.c +++ b/src/resource/resource-system.c @@ -77,7 +77,7 @@ static double __calculate_cpu_util(int64_t id, struct cpu_stat *prev, return util; } -static int system_get_avg_cpu_util(const struct resource *res, +static int system_get_avg_cpu_util(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -101,7 +101,7 @@ static int system_get_avg_cpu_util(const struct resource *res, return 0; } -static int system_get_per_cpu_util(const struct resource *res, +static int system_get_per_cpu_util(struct resource *res, const struct resource_attribute *attr, void *data) { @@ -143,7 +143,7 @@ static int system_get_per_cpu_util(const struct resource *res, return 0; } -static int system_get_cpu_num(const struct resource *res, +static int system_get_cpu_num(struct resource *res, const struct resource_attribute *attr, void *data) { diff --git a/src/util/resource.c b/src/util/resource.c index feea4d1..4f74cc0 100644 --- a/src/util/resource.c +++ b/src/util/resource.c @@ -963,7 +963,7 @@ int unset_resource_attr_interest(struct resource *resource, u_int64_t interest_m return 0; } -bool is_resource_attr_interested(const struct resource *resource, u_int64_t interest_mask) +bool is_resource_attr_interested(struct resource *resource, u_int64_t interest_mask) { if (!resource) return false; -- 2.7.4