pstore: restructure ramoops to support more trace
Subsystems (4)
PATCH 1/3 pstore: restructure ramoops to support more trace
From: Zhang Yanmin <[email protected]>
The patch restructure ramoops of pstore a little to support more user-defined tracers through ramoops. Here is reason we enhance ramoops:
pstore ramoops is a very import debug feature for mobile development. At present, ramoops has supported kdump, console and ftrace tracer. Sometimes, we need some special tracers such as recording cmd and data when driver send/receive. But now, it's hard to add new tracers into ramoops without touching the pstore core codes. So we restructure ramoops to let it more flexiable, more eailier to extend.
With this, we split the pstore codes and new tracers which are based on ramoops. Developer could add a new tracer based on ramoops standalone and pstore detects it automatically.
--- Documentation/ramoops.txt | 70 ++++++++++++++- arch/x86/kernel/vmlinux.lds.S | 9 ++ drivers/platform/chrome/chromeos_pstore.c | 2 +- fs/pstore/inode.c | 82 ++++++++++++++++- fs/pstore/internal.h | 1 + fs/pstore/ram.c | 142 +++++++++++++++++++++++------- fs/pstore/ram_core.c | 20 +++++ include/linux/pstore.h | 2 + include/linux/pstore_ram.h | 21 ++--- include/linux/pstore_ramoops.h | 65 ++++++++++++++ 10 files changed, 365 insertions(+), 49 deletions(-) create mode 100644 include/linux/pstore_ramoops.h
Documentation/ramoops.txt +69 -1
@@ -49,7 +49,7 @@ Setting the ramoops parameters can be done in 2 different manners: 2. Use a platform device and set the platform data. The parameters can then be set through that platform data. An example of doing that is: -#include <linux/pstore_ram.h> +#include <linux/pstore_ramoops.h> [...] static struct ramoops_platform_data ramoops_data = {
@@ -117,3 +117,71 @@ file. Here is an example of usage: 0 ffffffff811d9c54 ffffffff8101a7a0 __const_udelay <- native_machine_emergency_restart+0x110/0x1e0 0 ffffffff811d9c34 ffffffff811d9c80 __delay <- __const_udelay+0x30/0x40 0 ffffffff811d9d14 ffffffff811d9c3f delay_tsc <- __delay+0xf/0x20 + +6. Persistent record tracing + +Persistent record tracing might be useful for debugging software of hardware +related hangs. It has flexible usage allows developer to trace self-defined +record structure at self-defined tracepoint. After reboot, the record log is +stored in a "NAME-ramoops" file. Here is an example of usage: + +#include <linux/pstore_ramoops.h> +[...] + +struct norm_zone_test_record { + unsigned long val; + char str[32]; +}; + +static void print_record(struct seq_file *s, void *rec) +{ + struct norm_zone_test_record *record = rec; + seq_printf(s, "%s: %ld\n", + record->str, record->val); +} + +DEFINE_PSTORE_RAMZONE(test_zone) = { + .size = 4096, + .name = "test_zone", + .item_size = sizeof(struct norm_zone_test_record), + .print_record = print_record, +}; + +static void add_test_record(char *str, unsigned long val) +{ + struct norm_zone_test_record *record; + record = persistent_ram_new_record(test_zone.prz); + if (record) { + record->val = val; + strcpy(record->str, str); + } +} + +static int test_cpufreq_transition(struct notifier_block *nb, + unsigned long event, void *data) +{ + add_test_record("cpufreq transition", event); + return 0; +} + +static struct notifier_block freq_transition = { + .notifier_call = test_cpufreq_transition, +}; + +static int __init norm_zone_test_init(void) +{ + cpufreq_register_notifier(&freq_transition, + CPUFREQ_TRANSITION_NOTIFIER); + return 0; +} +module_init(norm_zone_test_init); + +Record trace use the reserved memory by ramoops. For the most compatibility, +user could use Chapter 2's methods to define the ramoops paramters, then +enlarge the defined mem_size with ramoops_norm_zones_size(), e.g.: + +#include <linux/memblock.h> +#include <linux/pstore_ramoops.h> + +memblock_reserve(ramoops_data.mem_address, ramoops_data.mem_size + + ramoops_norm_zones_size(NULL));
arch/x86/kernel/vmlinux.lds.S +9 -0
@@ -302,6 +302,15 @@ SECTIONS NOSAVE_DATA } #endif +#ifdef CONFIG_PSTORE_RAM + /* ramoops zone */ + . = ALIGN(8); + .ram_zone : AT(ADDR(.ram_zone) - LOAD_OFFSET) { + __ramoops_zone_start = .; + *(.ram_zone) + __ramoops_zone_end = .; + } +#endif /* BSS */ . = ALIGN(PAGE_SIZE);
drivers/platform/chrome/chromeos_pstore.c +1 -1
@@ -11,7 +11,7 @@#include <linux/dmi.h> #include <linux/module.h> #include <linux/platform_device.h> -#include <linux/pstore_ram.h> +#include <linux/pstore_ramoops.h> static struct dmi_system_id chromeos_pstore_dmi_table[]__initdata = { {
fs/pstore/inode.c +81 -1
112 lines not on this page · raw message
fs/pstore/internal.h +1 -0
@@ -4,6 +4,7 @@#include <linux/types.h> #include <linux/time.h> #include <linux/pstore.h> +#include <linux/pstore_ramoops.h> #if NR_CPUS <=2 && defined(CONFIG_ARM_THUMB )#define PSTORE_CPU_IN_IP 0x1
fs/pstore/ram.c +112 -30
249 lines not on this page · raw message
fs/pstore/ram_core.c +20 -0
@@ -30,6 +30,7 @@ struct persistent_ram_buffer {uint32_t sig;atomic_t start;atomic_t size; +uint32_t record_size;uint8_t data[0 ]; };
@@ -356,6 +357,19 @@ int notrace persistent_ram_write(struct persistent_ram_zone *prz,return count; } +notrace void *persistent_ram_new_record(struct persistent_ram_zone *prz) +{ +size_t record_size; + +if (!prz) +return NULL ; + + record_size = prz->buffer->record_size; +buffer_size_add (prz, record_size); +return (void *)(prz->buffer->data + +buffer_start_add (prz, record_size)); +} +size_t persistent_ram_old_size (struct persistent_ram_zone *prz) {return prz->old_log_size;
@@ -380,6 +394,12 @@ void persistent_ram_zap(struct persistent_ram_zone *prz)persistent_ram_update_header_ecc (prz); } +void persistent_ram_set_record_size (struct persistent_ram_zone *prz, +uint32_t record_size) +{ + prz->buffer->record_size = record_size; +} +static void *persistent_ram_vmap (phys_addr_t start,size_t size) {struct page **pages;
include/linux/pstore.h +2 -0
@@ -39,6 +39,8 @@ enum pstore_type_id {PSTORE_TYPE_PPC_RTAS =4 ,PSTORE_TYPE_PPC_OF =5 ,PSTORE_TYPE_PPC_COMMON =6 , +/* normal ram zones */ +PSTORE_TYPE_NORM =7 , PSTORE_TYPE_UNKNOWN = 255 };
include/linux/pstore_ram.h +5 -16
@@ -22,6 +22,7 @@#include <linux/list.h> #include <linux/types.h> #include <linux/init.h> +#include <linux/pstore.h> struct persistent_ram_buffer ;struct rs_control ;
@@ -59,6 +60,10 @@ void persistent_ram_zap(struct persistent_ram_zone *prz);int persistent_ram_write (struct persistent_ram_zone *prz,const void *s,unsigned int count); +void persistent_ram_set_record_size (struct persistent_ram_zone *prz, +uint32_t record_size); + +void *persistent_ram_new_record (struct persistent_ram_zone *prz);void persistent_ram_save_old (struct persistent_ram_zone *prz);size_t persistent_ram_old_size (struct persistent_ram_zone *prz);
@@ -67,20 +72,4 @@ void persistent_ram_free_old(struct persistent_ram_zone *prz);ssize_t persistent_ram_ecc_string (struct persistent_ram_zone *prz,char *str,size_t len); -/* -* Ramoops platform data -* @mem_size memory size for ramoops -* @mem_address physical memory address to contain ramoops -*/ - -struct ramoops_platform_data { -unsigned long mem_size; -unsigned long mem_address; -unsigned long record_size; -unsigned long console_size; -unsigned long ftrace_size; -int dump_oops; -struct persistent_ram_ecc_info ecc_info; -}; -#endif
include/linux/pstore_ramoops.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH 2/3 pstore: add seq_ops for norm zone
Some developers want to output the pstore record trace flexible. So add seq_ops into ramoops_zone in case users would make private output format.
--- fs/pstore/inode.c | 10 ++++++++-- include/linux/pstore_ramoops.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-)
fs/pstore/inode.c +8 -2
@@ -207,14 +207,20 @@ static ssize_t pstore_file_read(struct file *file, char __user *userbuf,static int pstore_file_open (struct inode *inode,struct file *file) {struct pstore_private *ps = inode->i_private; +struct ramoops_context *cxt = ps->psi->data; +struct ramoops_zone *zones = cxt->zones;struct seq_file *sf;int err;const struct seq_operations *sops =NULL ;if (ps->type ==PSTORE_TYPE_FTRACE ) sops = &pstore_ftrace_seq_ops; -if (ps->type ==PSTORE_TYPE_NORM ) - sops = &pstore_seq_ops; +if (ps->type ==PSTORE_TYPE_NORM ) { +if (zones[ps->id].seq_ops) + sops = zones[ps->id].seq_ops; +else + sops = &pstore_seq_ops; + } err =seq_open (file, sops);if (err <0 )
include/linux/pstore_ramoops.h +1 -0
@@ -32,6 +32,7 @@ struct ramoops_zone {struct persistent_ram_zone *prz;int item_size;void (*print_record)(struct seq_file *s,void *record); +struct seq_operations *seq_ops; };/*
Signature · 1 line
1.8.3.2
PATCH 1/1 pstore: support current records dump in ramoops
In reply to Liu ShuoXdump the records in runtime is useful sometime. We could check the records and understand driver's and device's status.
--- fs/pstore/inode.c | 32 ++++++++++++++++++++++++++------ fs/pstore/internal.h | 3 ++- fs/pstore/platform.c | 39 ++++++++++++++++++++++++++++++--------- fs/pstore/ram.c | 18 ++++++++++++++++++ fs/pstore/ram_core.c | 10 ++++++++++ include/linux/pstore.h | 2 ++ include/linux/pstore_ram.h | 2 ++ 7 files changed, 90 insertions(+), 16 deletions(-)
fs/pstore/inode.c +26 -6
@@ -48,10 +48,11 @@ struct pstore_private {struct list_head list;struct pstore_info *psi;enum pstore_type_id type; +int curr;u64 id;int count;ssize_t size; -char data[]; +char *data; };struct pstore_seq_data {
@@ -220,6 +221,14 @@ static int pstore_file_open(struct inode *inode, struct file *file) sops = zones[ps->id].seq_ops; else sops = &pstore_seq_ops; +if (ps->curr) { +/* +* Update size again as current buffer +* size might be changed. +*/ + inode->i_size = ps->size = +persistent_ram_size (cxt->norm_przs[ps->id]); + } } err =seq_open (file, sops);
@@ -256,12 +265,16 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry) {struct pstore_private *p = dentry->d_inode->i_private; +if (p->curr) + goto unlink;if (p->psi->erase) p->psi->erase (p->type, p->id, p->count, dentry->d_inode->i_ctime, p->psi);else return -EPERM ; +kfree (p->data); +unlink:return simple_unlink (dir, dentry); }
@@ -357,7 +370,7 @@ int pstore_is_mounted(void)*/ int pstore_mkfile (enum pstore_type_id type,char *psname,u64 id,int count,char *data,bool compressed,size_t size, -struct timespec time,struct pstore_info *psi) +struct timespec time,struct pstore_info *psi,bool curr) {struct dentry *root = pstore_sb->s_root;struct dentry *dentry;
@@ -373,14 +386,15 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,list_for_each_entry (pos, &allpstore, list) {if (pos->type == type && pos->id == id && - pos->psi == psi) { + pos->psi == psi && + pos->curr == curr) { rc = -EEXIST ;break ; } }spin_unlock_irqrestore (&allpstore_lock, flags);if (rc) -return rc; + goto fail; rc = -ENOMEM ; inode =pstore_get_inode (pstore_sb);
@@ -388,13 +402,15 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count, goto fail; inode->i_mode =S_IFREG |0444 ; inode->i_fop = &pstore_file_operations; - private =kmalloc (sizeof *private + size,GFP_KERNEL ); + private =kmalloc (sizeof (*private),GFP_KERNEL );if (!private) goto fail_alloc; private->type = type; private->id = id; private->count = count; private->psi = psi; + private->curr = curr; + private->data = data;switch (type) {case PSTORE_TYPE_DMESG :
@@ -430,13 +446,15 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,break ; } +if (curr) +strcat (name,"_cur" ); +mutex_lock (&root->d_inode->i_mutex); dentry =d_alloc_name (root, name);if (!dentry) goto fail_lockedalloc; -memcpy (private->data, data, size); inode->i_size = private->size = size; inode->i_private = private;
@@ -461,6 +479,7 @@ fail_alloc:iput (inode); fail: +kfree (data);return rc; }
@@ -493,6 +512,7 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent)return -ENOMEM ;pstore_get_records (0 ); +pstore_get_cur_records ();return 0 ; }
fs/pstore/internal.h +2 -1
@@ -50,10 +50,11 @@ extern struct pstore_info *psinfo;extern void pstore_set_kmsg_bytes (int );extern void pstore_get_records (int ); +extern void pstore_get_cur_records (void );extern int pstore_mkfile (enum pstore_type_id ,char *psname,u64 id,int count,char *data,bool compressed,size_t size,struct timespec time, -struct pstore_info *psi); +struct pstore_info *psi,bool curr);extern int pstore_is_mounted (void );#endif
fs/pstore/platform.c +30 -9
@@ -439,8 +439,10 @@ int pstore_register(struct pstore_info *psi)allocate_buf_for_compression (); -if (pstore_is_mounted ()) +if (pstore_is_mounted ()) {pstore_get_records (0 ); +pstore_get_cur_records (); + }kmsg_dump_register (&pstore_dumper);
@@ -498,7 +500,13 @@ void pstore_get_records(int quiet)if (unzipped_len >0 ) {kfree (buf); - buf = big_oops_buf; + buf =kmalloc (unzipped_len,GFP_KERNEL ); +if (!buf) { +if (!quiet) + failed++; +continue ; + } +memcpy (buf, big_oops_buf, unzipped_len); size = unzipped_len; compressed = false; }else {
@@ -508,15 +516,10 @@ void pstore_get_records(int quiet) } } rc =pstore_mkfile (type, psi->name, id, count, buf, - compressed, (size_t )size, time, psi); -if (unzipped_len <0 ) { -/* Free buffer other than big oops */ -kfree (buf); - buf =NULL ; - }else - unzipped_len =-1 ; + compressed, (size_t )size, time, psi, false);if (rc && (rc != -EEXIST || !quiet)) failed++; + unzipped_len =-1 ; }if (psi->close) psi->close (psi);
@@ -528,6 +531,24 @@ out: failed, psi->name); } +void pstore_get_cur_records (void ) +{ +struct pstore_info *psi = psinfo; +ssize_t size; +char *buf =NULL ; +struct timespec time = {0 }; +u64 id =0 ; +int rc; + +if (!psi) +return ; + +while (size = psi->read_curr (&id,PSTORE_TYPE_NORM , &buf, psi), buf) { + rc =pstore_mkfile (PSTORE_TYPE_NORM , psi->name, id -1 ,0 , buf, +0 , (size_t )size, time, psi, true); + } +} +static void pstore_dowork (struct work_struct *work) {pstore_get_records (1 );
fs/pstore/ram.c +18 -0
@@ -141,6 +141,23 @@ static void ramoops_read_kmsg_hdr(char *buffer, struct timespec *time, } } +/* only support PSTORE_TYPE_NORM type ram zone */ +static ssize_t ramoops_pstore_read_current (u64 *id,enum pstore_type_id type, +char **buf,struct pstore_info *psi) +{ +struct ramoops_context *cxt = psi->data; +struct persistent_ram_zone *prz; + +if (type !=PSTORE_TYPE_NORM || (*id >= cxt->norm_num)) { + *buf =NULL ; +return 0 ; + } + prz = cxt->norm_przs[(*id)++]; + *buf =persistent_ram_buffer (prz); + +return persistent_ram_size (prz); +} + static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, int *count, struct timespec *time, char **buf, bool *compressed,
@@ -306,6 +323,7 @@ static struct ramoops_context oops_cxt = { .name = "ramoops", .open = ramoops_pstore_open, .read = ramoops_pstore_read, + .read_curr = ramoops_pstore_read_current, .write_buf = ramoops_pstore_write_buf, .erase = ramoops_pstore_erase, },
fs/pstore/ram_core.c +10 -0
@@ -46,6 +46,11 @@ static inline size_t buffer_start(struct persistent_ram_zone *prz)return atomic_read (&prz->buffer->start); } +void *persistent_ram_buffer (struct persistent_ram_zone *prz) +{ +return prz->buffer->data; +} +/* increase and wrap the start pointer, returning the old value */ static size_t buffer_start_add_atomic (struct persistent_ram_zone *prz,size_t a) {
@@ -370,6 +375,11 @@ notrace void *persistent_ram_new_record(struct persistent_ram_zone *prz) buffer_start_add(prz, record_size)); } +size_t persistent_ram_size (struct persistent_ram_zone *prz) +{ +return buffer_size (prz); +} +size_t persistent_ram_old_size (struct persistent_ram_zone *prz) {return prz->old_log_size;
include/linux/pstore.h +2 -0
@@ -59,6 +59,8 @@ struct pstore_info {ssize_t (*read)(u64 *id,enum pstore_type_id *type,int *count,struct timespec *time,char **buf,bool *compressed,struct pstore_info *psi); +ssize_t (*read_curr)(u64 *id,enum pstore_type_id type, +char **buf,struct pstore_info *psi); int (*write)(enum pstore_type_id type, enum kmsg_dump_reason reason, u64 *id, unsigned int part, int count, bool compressed,
include/linux/pstore_ram.h +2 -0
@@ -57,6 +57,7 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, u32 sig, struct persistent_ram_ecc_info *ecc_info);void persistent_ram_free (struct persistent_ram_zone *prz);void persistent_ram_zap (struct persistent_ram_zone *prz); +void *persistent_ram_buffer (struct persistent_ram_zone *prz);int persistent_ram_write (struct persistent_ram_zone *prz,const void *s,unsigned int count);
@@ -67,6 +68,7 @@ void *persistent_ram_new_record(struct persistent_ram_zone *prz);void persistent_ram_save_old (struct persistent_ram_zone *prz);size_t persistent_ram_old_size (struct persistent_ram_zone *prz); +size_t persistent_ram_size (struct persistent_ram_zone *prz);void *persistent_ram_old (struct persistent_ram_zone *prz);void persistent_ram_free_old (struct persistent_ram_zone *prz); ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz,
Signature · 1 line
1.8.3.2