Skip to contentSkip to conversation

perfmon: sysfs interface

PATCH In review [email protected] 1 participant 1 message Nov 26, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 11/24 perfmon: sysfs interface

This patch adds the sysfs interface to the perfmon subsystem. It is used for configuration of the interface. It exposes the PMU register mappings and various attributes of the subsystem.

--

perfmon/perfmon_init.c +3 -0
Index: o3/perfmon/perfmon_init.c
===================================================================
@@ -62,6 +62,9 @@
 	if (pfm_init_fs())
 		goto error_disable;
 
+ 	if (pfm_init_sysfs())
+ 		goto error_disable;
+
 	/*
 	 * one time, arch-specific global initialization
 	 */
perfmon/perfmon_sysfs.c new file +344 -0

344 lines not on this page · raw message

perfmon/perfmon_priv.h +2 -0
Index: o3/perfmon/perfmon_priv.h
===================================================================
@@ -52,6 +52,8 @@
 
 void pfm_free_context(struct pfm_context *ctx);
 
+ssize_t pfm_sysfs_res_show(char *buf, size_t sz, int what);
+
 int pfm_pmu_acquire(struct pfm_context *ctx);
 void pfm_pmu_release(void);
 
perfmon/perfmon_res.c +33 -0
Index: o3/perfmon/perfmon_res.c
===================================================================
@@ -188,3 +188,36 @@
 	spin_unlock_irqrestore(&pfm_res_lock, flags);
 }
 EXPORT_SYMBOL(pfm_session_allcpus_release);
+
+/**
+ * pfm_sysfs_res_show - return currnt resourcde usage for sysfs
+ * @buf: buffer to hold string in return
+ * @sz: size of buf
+ * @what: what to produce
+ *        what=0 : thread_sessions
+ *        what=1 : cpus_weight(sys_cpumask)
+ *        what=2 : smpl_buf_mem_cur
+ *        what=3 : pmu model name
+ *
+ * called from perfmon_sysfs.c
+ * return number of bytes written into buf (up to sz)
+ */
+ssize_t pfm_sysfs_res_show(char *buf, size_t sz, int what)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&pfm_res_lock, flags);
+
+	switch (what) {
+	case 0: snprintf(buf, sz, "%u\n", pfm_res.thread_sessions);
+		break;
+	case 1: snprintf(buf, sz, "%d\n", cpus_weight(pfm_res.sys_cpumask));
+		break;
+	case 3:
+		snprintf(buf, sz, "%s\n",
+			pfm_pmu_conf ?	pfm_pmu_conf->pmu_name
+				     :	"unknown\n");
+	}
+	spin_unlock_irqrestore(&pfm_res_lock, flags);
+	return strlen(buf);
+}
perfmon/perfmon_pmu.c +4 -0
Index: o3/perfmon/perfmon_pmu.c
===================================================================
@@ -164,6 +164,10 @@
 	pfm_pmu_conf = cfg;
 	pfm_pmu_conf->ovfl_mask = (1ULL << cfg->counter_width) - 1;
 
+	ret = pfm_sysfs_add_pmu(pfm_pmu_conf);
+	if (ret)
+		pfm_pmu_conf = NULL;
+
 unlock:
 	spin_unlock(&pfm_pmu_conf_lock);