Skip to contentSkip to conversation

perfmon2 minimal v2: sysfs interface

PATCH In review [email protected] 1 participant 1 message Jun 17, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 10/19 perfmon2 minimal v2: sysfs interface

This patch adds the sysfs interface to the perfmon2 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: o/perfmon/perfmon_init.c
===================================================================
@@ -62,6 +62,9 @@
 	if (pfm_init_fs())
 		goto error_disable;
 
+	if (pfm_init_sysfs())
+		goto error_disable;
+
 	/* not critical, so no error checking */
 	pfm_init_debugfs();
 
perfmon/perfmon_sysfs.c new file +344 -0

344 lines not on this page · raw message

perfmon/perfmon_priv.h +2 -0
Index: o/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(void);
 void pfm_pmu_release(void);
 
perfmon/perfmon_res.c +33 -0
Index: o/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/Makefile +2 -1
Index: o/perfmon/Makefile
===================================================================
@@ -5,4 +5,5 @@
 obj-$(CONFIG_PERFMON) = perfmon_ctx.o perfmon_ctxsw.o		\
 			perfmon_file.o perfmon_attach.o 	\
 			perfmon_res.o perfmon_init.o		\
-			perfmon_intr.o perfmon_pmu.o
+			perfmon_intr.o perfmon_pmu.o		\
+			perfmon_sysfs.o
perfmon/perfmon_pmu.c +4 -0
Index: o/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);
 
Documentation/ABI/testing/sysfs-perfmon new file +38 -0
Index: o/Documentation/ABI/testing/sysfs-perfmon
===================================================================
@@ -0,0 +1,38 @@
+What:		/sys/kernel/perfmon
+Date:		June 2008
+KernelVersion:	2.6.26
+Contact:	[email protected]
+
+Description:	provide the configuration interface for the perfmon2 subsystems.
+	        The tree contains information about the detected hardware, current
+		state of the subsystem as well as some configuration parameters.
+
+		The tree consists of the following entries:
+
+   	/sys/kernel/perfmon/version (read-only):
+
+		Perfmon2 interface revision number.
+
+	/sys/kernel/perfmon/task_sessions_count (read-only):
+
+		Number of per-thread contexts currently attached to threads.
+
+	/sys/kernel/perfmon/debug (read-write):
+
+		Enable perfmon2 debugging output via klogd. Debug messages produced during
+		PMU interrupt handling are not controlled by this entry. The traces a rate-limited
+		to avoid flooding of the console. It is possible to change the throttling
+	        via /proc/sys/kernel/printk_ratelimit. The value is interpreted as a bitmask.
+		Each bit enables a particular type of debug messages. Refer to the file
+		include/linux/perfmon_kern.h for more information
+
+	/sys/kernel/perfmon/task_group (read-write):
+
+		Users group allowed to create a per-thread context (session).
+   		-1 means any group. This control will be kept until we find a
+		package able to control capabilities via PAM.
+
+	/sys/kernel/perfmon/arg_mem_max(read-write):
+
+		Maximum size of vector arguments expressed in bytes. Can be modified
+		but must be at least a page. Default is PAGE_SIZE
Documentation/ABI/testing/sysfs-perfmon-pmu new file +46 -0

46 lines not on this page · raw message