mm: mm_event: make capture period configurable
authorMinchan Kim <minchan@google.com>
Mon, 6 Aug 2018 06:02:06 +0000 (15:02 +0900)
committerPDO SCM Team <hudsoncm@motorola.com>
Fri, 15 Nov 2019 06:58:39 +0000 (00:58 -0600)
This patch makes per-process mm event capture inteval configurable.
Defenderault is 500ms but admin can change it by below knob.

/sys/kernel/debug/mm_event/period_ms

The unit is millisecond.

Mot-CRs-fixed: (CR)

Bug: 80168800
Change-Id: I3b2de3dd5c4a519a2e5e20f1ef0d5f9a4c7afc8a
Signed-off-by: Minchan Kim <minchan@google.com>
Reviewed-on: https://gerrit.mot.com/1453719
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key

mm/mm_event.c

index f2ba7b9004aedfebfdb1a6528a092139a7d03625..5d5c90bbd3b9aace34738033b366b2a80d703ce1 100644 (file)
@@ -7,6 +7,8 @@
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/mm_event.h>
+/* msec */
+static unsigned long period_ms = 500;
 
 void mm_event_task_init(struct task_struct *tsk)
 {
@@ -27,7 +29,7 @@ static void record_stat(void)
                        memset(&current->mm_event[i], 0,
                                        sizeof(struct mm_event_task));
                }
-               current->next_period = jiffies + (HZ >> 1);
+               current->next_period = jiffies + msecs_to_jiffies(period_ms);
        }
 }
 
@@ -49,14 +51,43 @@ void mm_event_end(enum mm_event_type event, ktime_t start)
 
 static struct dentry *mm_event_root;
 
+static int period_ms_set(void *data, u64 val)
+{
+       if (val < 1 || val > ULONG_MAX)
+               return -EINVAL;
+
+       period_ms = (unsigned long)val;
+       return 0;
+}
+
+static int period_ms_get(void *data, u64 *val)
+{
+       *val = period_ms;
+       return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(period_ms_operations, period_ms_get,
+                       period_ms_set, "%llu\n");
+
 static int __init mm_event_init(void)
 {
+       struct dentry *entry;
+
        mm_event_root = debugfs_create_dir("mm_event", NULL);
        if (!mm_event_root) {
                pr_warn("debugfs dir <mm_event> creation failed\n");
                return PTR_ERR(mm_event_root);
        }
 
+       entry = debugfs_create_file("period_ms", 0644,
+                       mm_event_root, NULL, &period_ms_operations);
+
+       if (IS_ERR(entry)) {
+               pr_warn("debugfs file mm_event_task creation failed\n");
+               debugfs_remove_recursive(mm_event_root);
+               return PTR_ERR(entry);
+       }
+
        return 0;
 }
 subsys_initcall(mm_event_init);