Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1671887
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 04/25] tools lib api fs: Add sysfs__write_int function |
| Date | 2017-06-21 20:10 +0200 |
| Message-ID | <tUSeL-1fP-51@gated-at.bofh.it> (permalink) |
| References | <tUSeJ-1fP-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Kan Liang <Kan.liang@intel.com>
Add sysfs__write_int() to ease up writing int to sysfs. New interface
is:
int sysfs__write_int(const char *entry, int value);
Also, introducing filename__write_int() which is useful for new helpers
to write sysctl values.
Signed-off-by: Kan Liang <Kan.liang@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robert Elliott <elliott@hpe.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1495825538-5230-2-git-send-email-kan.liang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/api/fs/fs.c | 30 ++++++++++++++++++++++++++++++
tools/lib/api/fs/fs.h | 4 ++++
2 files changed, 34 insertions(+)
diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c
index 809c7721cd24..a7ecf8f469f4 100644
--- a/tools/lib/api/fs/fs.c
+++ b/tools/lib/api/fs/fs.c
@@ -387,6 +387,22 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep)
return err;
}
+int filename__write_int(const char *filename, int value)
+{
+ int fd = open(filename, O_WRONLY), err = -1;
+ char buf[64];
+
+ if (fd < 0)
+ return err;
+
+ sprintf(buf, "%d", value);
+ if (write(fd, buf, sizeof(buf)) == sizeof(buf))
+ err = 0;
+
+ close(fd);
+ return err;
+}
+
int procfs__read_str(const char *entry, char **buf, size_t *sizep)
{
char path[PATH_MAX];
@@ -480,3 +496,17 @@ int sysctl__read_int(const char *sysctl, int *value)
return filename__read_int(path, value);
}
+
+int sysfs__write_int(const char *entry, int value)
+{
+ char path[PATH_MAX];
+ const char *sysfs = sysfs__mountpoint();
+
+ if (!sysfs)
+ return -1;
+
+ if (snprintf(path, sizeof(path), "%s/%s", sysfs, entry) >= PATH_MAX)
+ return -1;
+
+ return filename__write_int(path, value);
+}
diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h
index 956c21127d1e..45605348461e 100644
--- a/tools/lib/api/fs/fs.h
+++ b/tools/lib/api/fs/fs.h
@@ -31,6 +31,8 @@ int filename__read_int(const char *filename, int *value);
int filename__read_ull(const char *filename, unsigned long long *value);
int filename__read_str(const char *filename, char **buf, size_t *sizep);
+int filename__write_int(const char *filename, int value);
+
int procfs__read_str(const char *entry, char **buf, size_t *sizep);
int sysctl__read_int(const char *sysctl, int *value);
@@ -38,4 +40,6 @@ int sysfs__read_int(const char *entry, int *value);
int sysfs__read_ull(const char *entry, unsigned long long *value);
int sysfs__read_str(const char *entry, char **buf, size_t *sizep);
int sysfs__read_bool(const char *entry, bool *value);
+
+int sysfs__write_int(const char *entry, int value);
#endif /* __API_FS__ */
--
2.9.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[GIT PULL 00/25] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 09/25] perf intel-pt: Fix missing stack clear Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 07/25] perf intel-pt: Move decoder error setting into one condition Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 23/25] perf intel-pt: Fix transactions_sample_type Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 04/25] tools lib api fs: Add sysfs__write_int function Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 05/25] perf stat: Add support to measure SMI cost Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 19/25] perf intel-pt: Add decoder support for ptwrite and power event packets Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 22/25] perf intel-pt: Remove redundant initial_skip checks Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 08/25] perf intel-pt: Improve sample timestamp Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 25/25] perf script: Fix message because field list option is -F not -f Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 20/25] perf intel-pt: Add reserved byte to CBR packet payload Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 11/25] perf intel-pt: Fix last_ip usage Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 14/25] perf intel-pt: Clear FUP flag on error Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 [PATCH 10/25] perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-21 20:10 +0200 Re: [GIT PULL 00/25] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2017-06-21 20:20 +0200
csiph-web