diff options
Diffstat (limited to 'kernel/trace/rv/rv.c')
| -rw-r--r-- | kernel/trace/rv/rv.c | 226 | 
1 files changed, 97 insertions, 129 deletions
| diff --git a/kernel/trace/rv/rv.c b/kernel/trace/rv/rv.c index e4077500a91d..1482e91c39f4 100644 --- a/kernel/trace/rv/rv.c +++ b/kernel/trace/rv/rv.c @@ -143,7 +143,7 @@  #include <linux/init.h>  #include <linux/slab.h> -#ifdef CONFIG_DA_MON_EVENTS +#ifdef CONFIG_RV_MON_EVENTS  #define CREATE_TRACE_POINTS  #include <rv_trace.h>  #endif @@ -165,7 +165,7 @@ struct dentry *get_monitors_root(void)  LIST_HEAD(rv_monitors_list);  static int task_monitor_count; -static bool task_monitor_slots[RV_PER_TASK_MONITORS]; +static bool task_monitor_slots[CONFIG_RV_PER_TASK_MONITORS];  int rv_get_task_monitor_slot(void)  { @@ -173,12 +173,12 @@ int rv_get_task_monitor_slot(void)  	lockdep_assert_held(&rv_interface_lock); -	if (task_monitor_count == RV_PER_TASK_MONITORS) +	if (task_monitor_count == CONFIG_RV_PER_TASK_MONITORS)  		return -EBUSY;  	task_monitor_count++; -	for (i = 0; i < RV_PER_TASK_MONITORS; i++) { +	for (i = 0; i < CONFIG_RV_PER_TASK_MONITORS; i++) {  		if (task_monitor_slots[i] == false) {  			task_monitor_slots[i] = true;  			return i; @@ -194,7 +194,7 @@ void rv_put_task_monitor_slot(int slot)  {  	lockdep_assert_held(&rv_interface_lock); -	if (slot < 0 || slot >= RV_PER_TASK_MONITORS) { +	if (slot < 0 || slot >= CONFIG_RV_PER_TASK_MONITORS) {  		WARN_ONCE(1, "RV releasing an invalid slot!: %d\n", slot);  		return;  	} @@ -210,9 +210,9 @@ void rv_put_task_monitor_slot(int slot)   * Monitors with a parent are nested,   * Monitors without a parent could be standalone or containers.   */ -bool rv_is_nested_monitor(struct rv_monitor_def *mdef) +bool rv_is_nested_monitor(struct rv_monitor *mon)  { -	return mdef->parent != NULL; +	return mon->parent != NULL;  }  /* @@ -223,16 +223,16 @@ bool rv_is_nested_monitor(struct rv_monitor_def *mdef)   * for enable()/disable(). Use this condition to find empty containers.   * Keep both conditions in case we have some non-compliant containers.   */ -bool rv_is_container_monitor(struct rv_monitor_def *mdef) +bool rv_is_container_monitor(struct rv_monitor *mon)  { -	struct rv_monitor_def *next; +	struct rv_monitor *next; -	if (list_is_last(&mdef->list, &rv_monitors_list)) +	if (list_is_last(&mon->list, &rv_monitors_list))  		return false; -	next = list_next_entry(mdef, list); +	next = list_next_entry(mon, list); -	return next->parent == mdef->monitor || !mdef->monitor->enable; +	return next->parent == mon || !mon->enable;  }  /* @@ -241,10 +241,10 @@ bool rv_is_container_monitor(struct rv_monitor_def *mdef)  static ssize_t monitor_enable_read_data(struct file *filp, char __user *user_buf, size_t count,  					loff_t *ppos)  { -	struct rv_monitor_def *mdef = filp->private_data; +	struct rv_monitor *mon = filp->private_data;  	const char *buff; -	buff = mdef->monitor->enabled ? "1\n" : "0\n"; +	buff = mon->enabled ? "1\n" : "0\n";  	return simple_read_from_buffer(user_buf, count, ppos, buff, strlen(buff)+1);  } @@ -252,14 +252,14 @@ static ssize_t monitor_enable_read_data(struct file *filp, char __user *user_buf  /*   * __rv_disable_monitor - disabled an enabled monitor   */ -static int __rv_disable_monitor(struct rv_monitor_def *mdef, bool sync) +static int __rv_disable_monitor(struct rv_monitor *mon, bool sync)  {  	lockdep_assert_held(&rv_interface_lock); -	if (mdef->monitor->enabled) { -		mdef->monitor->enabled = 0; -		if (mdef->monitor->disable) -			mdef->monitor->disable(); +	if (mon->enabled) { +		mon->enabled = 0; +		if (mon->disable) +			mon->disable();  		/*  		 * Wait for the execution of all events to finish. @@ -273,90 +273,90 @@ static int __rv_disable_monitor(struct rv_monitor_def *mdef, bool sync)  	return 0;  } -static void rv_disable_single(struct rv_monitor_def *mdef) +static void rv_disable_single(struct rv_monitor *mon)  { -	__rv_disable_monitor(mdef, true); +	__rv_disable_monitor(mon, true);  } -static int rv_enable_single(struct rv_monitor_def *mdef) +static int rv_enable_single(struct rv_monitor *mon)  {  	int retval;  	lockdep_assert_held(&rv_interface_lock); -	if (mdef->monitor->enabled) +	if (mon->enabled)  		return 0; -	retval = mdef->monitor->enable(); +	retval = mon->enable();  	if (!retval) -		mdef->monitor->enabled = 1; +		mon->enabled = 1;  	return retval;  } -static void rv_disable_container(struct rv_monitor_def *mdef) +static void rv_disable_container(struct rv_monitor *mon)  { -	struct rv_monitor_def *p = mdef; +	struct rv_monitor *p = mon;  	int enabled = 0;  	list_for_each_entry_continue(p, &rv_monitors_list, list) { -		if (p->parent != mdef->monitor) +		if (p->parent != mon)  			break;  		enabled += __rv_disable_monitor(p, false);  	}  	if (enabled)  		tracepoint_synchronize_unregister(); -	mdef->monitor->enabled = 0; +	mon->enabled = 0;  } -static int rv_enable_container(struct rv_monitor_def *mdef) +static int rv_enable_container(struct rv_monitor *mon)  { -	struct rv_monitor_def *p = mdef; +	struct rv_monitor *p = mon;  	int retval = 0;  	list_for_each_entry_continue(p, &rv_monitors_list, list) { -		if (retval || p->parent != mdef->monitor) +		if (retval || p->parent != mon)  			break;  		retval = rv_enable_single(p);  	}  	if (retval) -		rv_disable_container(mdef); +		rv_disable_container(mon);  	else -		mdef->monitor->enabled = 1; +		mon->enabled = 1;  	return retval;  }  /**   * rv_disable_monitor - disable a given runtime monitor - * @mdef: Pointer to the monitor definition structure. + * @mon: Pointer to the monitor definition structure.   *   * Returns 0 on success.   */ -int rv_disable_monitor(struct rv_monitor_def *mdef) +int rv_disable_monitor(struct rv_monitor *mon)  { -	if (rv_is_container_monitor(mdef)) -		rv_disable_container(mdef); +	if (rv_is_container_monitor(mon)) +		rv_disable_container(mon);  	else -		rv_disable_single(mdef); +		rv_disable_single(mon);  	return 0;  }  /**   * rv_enable_monitor - enable a given runtime monitor - * @mdef: Pointer to the monitor definition structure. + * @mon: Pointer to the monitor definition structure.   *   * Returns 0 on success, error otherwise.   */ -int rv_enable_monitor(struct rv_monitor_def *mdef) +int rv_enable_monitor(struct rv_monitor *mon)  {  	int retval; -	if (rv_is_container_monitor(mdef)) -		retval = rv_enable_container(mdef); +	if (rv_is_container_monitor(mon)) +		retval = rv_enable_container(mon);  	else -		retval = rv_enable_single(mdef); +		retval = rv_enable_single(mon);  	return retval;  } @@ -367,7 +367,7 @@ int rv_enable_monitor(struct rv_monitor_def *mdef)  static ssize_t monitor_enable_write_data(struct file *filp, const char __user *user_buf,  					 size_t count, loff_t *ppos)  { -	struct rv_monitor_def *mdef = filp->private_data; +	struct rv_monitor *mon = filp->private_data;  	int retval;  	bool val; @@ -378,9 +378,9 @@ static ssize_t monitor_enable_write_data(struct file *filp, const char __user *u  	mutex_lock(&rv_interface_lock);  	if (val) -		retval = rv_enable_monitor(mdef); +		retval = rv_enable_monitor(mon);  	else -		retval = rv_disable_monitor(mdef); +		retval = rv_disable_monitor(mon);  	mutex_unlock(&rv_interface_lock); @@ -399,12 +399,12 @@ static const struct file_operations interface_enable_fops = {  static ssize_t monitor_desc_read_data(struct file *filp, char __user *user_buf, size_t count,  				      loff_t *ppos)  { -	struct rv_monitor_def *mdef = filp->private_data; +	struct rv_monitor *mon = filp->private_data;  	char buff[256];  	memset(buff, 0, sizeof(buff)); -	snprintf(buff, sizeof(buff), "%s\n", mdef->monitor->description); +	snprintf(buff, sizeof(buff), "%s\n", mon->description);  	return simple_read_from_buffer(user_buf, count, ppos, buff, strlen(buff) + 1);  } @@ -419,37 +419,37 @@ static const struct file_operations interface_desc_fops = {   * the monitor dir, where the specific options of the monitor   * are exposed.   */ -static int create_monitor_dir(struct rv_monitor_def *mdef, struct rv_monitor_def *parent) +static int create_monitor_dir(struct rv_monitor *mon, struct rv_monitor *parent)  {  	struct dentry *root = parent ? parent->root_d : get_monitors_root(); -	const char *name = mdef->monitor->name; +	const char *name = mon->name;  	struct dentry *tmp;  	int retval; -	mdef->root_d = rv_create_dir(name, root); -	if (!mdef->root_d) +	mon->root_d = rv_create_dir(name, root); +	if (!mon->root_d)  		return -ENOMEM; -	tmp = rv_create_file("enable", RV_MODE_WRITE, mdef->root_d, mdef, &interface_enable_fops); +	tmp = rv_create_file("enable", RV_MODE_WRITE, mon->root_d, mon, &interface_enable_fops);  	if (!tmp) {  		retval = -ENOMEM;  		goto out_remove_root;  	} -	tmp = rv_create_file("desc", RV_MODE_READ, mdef->root_d, mdef, &interface_desc_fops); +	tmp = rv_create_file("desc", RV_MODE_READ, mon->root_d, mon, &interface_desc_fops);  	if (!tmp) {  		retval = -ENOMEM;  		goto out_remove_root;  	} -	retval = reactor_populate_monitor(mdef); +	retval = reactor_populate_monitor(mon);  	if (retval)  		goto out_remove_root;  	return 0;  out_remove_root: -	rv_remove(mdef->root_d); +	rv_remove(mon->root_d);  	return retval;  } @@ -458,13 +458,12 @@ out_remove_root:   */  static int monitors_show(struct seq_file *m, void *p)  { -	struct rv_monitor_def *mon_def = p; +	struct rv_monitor *mon = container_of(p, struct rv_monitor, list); -	if (mon_def->parent) -		seq_printf(m, "%s:%s\n", mon_def->parent->name, -			   mon_def->monitor->name); +	if (mon->parent) +		seq_printf(m, "%s:%s\n", mon->parent->name, mon->name);  	else -		seq_printf(m, "%s\n", mon_def->monitor->name); +		seq_printf(m, "%s\n", mon->name);  	return 0;  } @@ -496,13 +495,13 @@ static void *available_monitors_next(struct seq_file *m, void *p, loff_t *pos)   */  static void *enabled_monitors_next(struct seq_file *m, void *p, loff_t *pos)  { -	struct rv_monitor_def *m_def = p; +	struct rv_monitor *mon = p;  	(*pos)++; -	list_for_each_entry_continue(m_def, &rv_monitors_list, list) { -		if (m_def->monitor->enabled) -			return m_def; +	list_for_each_entry_continue(mon, &rv_monitors_list, list) { +		if (mon->enabled) +			return mon;  	}  	return NULL; @@ -510,7 +509,7 @@ static void *enabled_monitors_next(struct seq_file *m, void *p, loff_t *pos)  static void *enabled_monitors_start(struct seq_file *m, loff_t *pos)  { -	struct rv_monitor_def *m_def; +	struct rv_monitor *mon;  	loff_t l;  	mutex_lock(&rv_interface_lock); @@ -518,15 +517,15 @@ static void *enabled_monitors_start(struct seq_file *m, loff_t *pos)  	if (list_empty(&rv_monitors_list))  		return NULL; -	m_def = list_entry(&rv_monitors_list, struct rv_monitor_def, list); +	mon = list_entry(&rv_monitors_list, struct rv_monitor, list);  	for (l = 0; l <= *pos; ) { -		m_def = enabled_monitors_next(m, m_def, &l); -		if (!m_def) +		mon = enabled_monitors_next(m, mon, &l); +		if (!mon)  			break;  	} -	return m_def; +	return mon;  }  /* @@ -566,13 +565,13 @@ static const struct file_operations available_monitors_ops = {   */  static void disable_all_monitors(void)  { -	struct rv_monitor_def *mdef; +	struct rv_monitor *mon;  	int enabled = 0;  	mutex_lock(&rv_interface_lock); -	list_for_each_entry(mdef, &rv_monitors_list, list) -		enabled += __rv_disable_monitor(mdef, false); +	list_for_each_entry(mon, &rv_monitors_list, list) +		enabled += __rv_disable_monitor(mon, false);  	if (enabled) {  		/* @@ -598,7 +597,7 @@ static ssize_t enabled_monitors_write(struct file *filp, const char __user *user  				      size_t count, loff_t *ppos)  {  	char buff[MAX_RV_MONITOR_NAME_SIZE + 2]; -	struct rv_monitor_def *mdef; +	struct rv_monitor *mon;  	int retval = -EINVAL;  	bool enable = true;  	char *ptr, *tmp; @@ -633,17 +632,17 @@ static ssize_t enabled_monitors_write(struct file *filp, const char __user *user  	if (tmp)  		ptr = tmp+1; -	list_for_each_entry(mdef, &rv_monitors_list, list) { -		if (strcmp(ptr, mdef->monitor->name) != 0) +	list_for_each_entry(mon, &rv_monitors_list, list) { +		if (strcmp(ptr, mon->name) != 0)  			continue;  		/*  		 * Monitor found!  		 */  		if (enable) -			retval = rv_enable_monitor(mdef); +			retval = rv_enable_monitor(mon);  		else -			retval = rv_disable_monitor(mdef); +			retval = rv_disable_monitor(mon);  		if (!retval)  			retval = count; @@ -675,8 +674,6 @@ static bool __read_mostly monitoring_on;   */  bool rv_monitoring_on(void)  { -	/* Ensures that concurrent monitors read consistent monitoring_on */ -	smp_rmb();  	return READ_ONCE(monitoring_on);  } @@ -696,25 +693,21 @@ static ssize_t monitoring_on_read_data(struct file *filp, char __user *user_buf,  static void turn_monitoring_off(void)  {  	WRITE_ONCE(monitoring_on, false); -	/* Ensures that concurrent monitors read consistent monitoring_on */ -	smp_wmb();  }  static void reset_all_monitors(void)  { -	struct rv_monitor_def *mdef; +	struct rv_monitor *mon; -	list_for_each_entry(mdef, &rv_monitors_list, list) { -		if (mdef->monitor->enabled && mdef->monitor->reset) -			mdef->monitor->reset(); +	list_for_each_entry(mon, &rv_monitors_list, list) { +		if (mon->enabled && mon->reset) +			mon->reset();  	}  }  static void turn_monitoring_on(void)  {  	WRITE_ONCE(monitoring_on, true); -	/* Ensures that concurrent monitors read consistent monitoring_on */ -	smp_wmb();  }  static void turn_monitoring_on_with_reset(void) @@ -768,10 +761,9 @@ static const struct file_operations monitoring_on_fops = {  	.read   = monitoring_on_read_data,  }; -static void destroy_monitor_dir(struct rv_monitor_def *mdef) +static void destroy_monitor_dir(struct rv_monitor *mon)  { -	reactor_cleanup_monitor(mdef); -	rv_remove(mdef->root_d); +	rv_remove(mon->root_d);  }  /** @@ -783,7 +775,7 @@ static void destroy_monitor_dir(struct rv_monitor_def *mdef)   */  int rv_register_monitor(struct rv_monitor *monitor, struct rv_monitor *parent)  { -	struct rv_monitor_def *r, *p = NULL; +	struct rv_monitor *r;  	int retval = 0;  	if (strlen(monitor->name) >= MAX_RV_MONITOR_NAME_SIZE) { @@ -795,49 +787,31 @@ int rv_register_monitor(struct rv_monitor *monitor, struct rv_monitor *parent)  	mutex_lock(&rv_interface_lock);  	list_for_each_entry(r, &rv_monitors_list, list) { -		if (strcmp(monitor->name, r->monitor->name) == 0) { +		if (strcmp(monitor->name, r->name) == 0) {  			pr_info("Monitor %s is already registered\n", monitor->name);  			retval = -EEXIST;  			goto out_unlock;  		}  	} -	if (parent) { -		list_for_each_entry(r, &rv_monitors_list, list) { -			if (strcmp(parent->name, r->monitor->name) == 0) { -				p = r; -				break; -			} -		} -	} - -	if (p && rv_is_nested_monitor(p)) { +	if (parent && rv_is_nested_monitor(parent)) {  		pr_info("Parent monitor %s is already nested, cannot nest further\n",  			parent->name);  		retval = -EINVAL;  		goto out_unlock;  	} -	r = kzalloc(sizeof(struct rv_monitor_def), GFP_KERNEL); -	if (!r) { -		retval = -ENOMEM; -		goto out_unlock; -	} - -	r->monitor = monitor; -	r->parent = parent; +	monitor->parent = parent; -	retval = create_monitor_dir(r, p); -	if (retval) { -		kfree(r); -		goto out_unlock; -	} +	retval = create_monitor_dir(monitor, parent); +	if (retval) +		return retval;  	/* keep children close to the parent for easier visualisation */ -	if (p) -		list_add(&r->list, &p->list); +	if (parent) +		list_add(&monitor->list, &parent->list);  	else -		list_add_tail(&r->list, &rv_monitors_list); +		list_add_tail(&monitor->list, &rv_monitors_list);  out_unlock:  	mutex_unlock(&rv_interface_lock); @@ -852,17 +826,11 @@ out_unlock:   */  int rv_unregister_monitor(struct rv_monitor *monitor)  { -	struct rv_monitor_def *ptr, *next; -  	mutex_lock(&rv_interface_lock); -	list_for_each_entry_safe(ptr, next, &rv_monitors_list, list) { -		if (strcmp(monitor->name, ptr->monitor->name) == 0) { -			rv_disable_monitor(ptr); -			list_del(&ptr->list); -			destroy_monitor_dir(ptr); -		} -	} +	rv_disable_monitor(monitor); +	list_del(&monitor->list); +	destroy_monitor_dir(monitor);  	mutex_unlock(&rv_interface_lock);  	return 0; | 
