From: tip-bot for Kan Liang <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: kan.liang@intel.com, peterz@infradead.org, acme@redhat.com,
jolsa@kernel.org, hpa@zytor.com, ak@linux.intel.com,
elliott@hpe.com, linux-kernel@vger.kernel.org,
Kan.liang@intel.com, tglx@linutronix.de, eranian@google.com,
mingo@kernel.org
Subject: [tip:perf/core] tools lib api fs: Add sysfs__write_int function
Date: Wed, 21 Jun 2017 11:17:44 -0700 [thread overview]
Message-ID: <tip-3b00ea938653d136c8e4bcbe9722d954e128ce2e@git.kernel.org> (raw)
In-Reply-To: <1495825538-5230-2-git-send-email-kan.liang@intel.com>
Commit-ID: 3b00ea938653d136c8e4bcbe9722d954e128ce2e
Gitweb: http://git.kernel.org/tip/3b00ea938653d136c8e4bcbe9722d954e128ce2e
Author: Kan Liang <Kan.liang@intel.com>
AuthorDate: Fri, 26 May 2017 12:05:37 -0700
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:27 -0300
tools lib api fs: Add sysfs__write_int function
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 809c772..a7ecf8f 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 956c211..4560534 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__ */
next prev parent reply other threads:[~2017-06-21 18:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-26 19:05 [PATCH V2 0/2] measure SMI cost (user) kan.liang
2017-05-26 19:05 ` [PATCH V2 1/2] tools lib api fs: Add sysfs__write_int function kan.liang
2017-06-21 18:17 ` tip-bot for Kan Liang [this message]
2017-05-26 19:05 ` [PATCH V2 2/2] perf stat: Add support to measure SMI cost kan.liang
2017-06-21 18:18 ` [tip:perf/core] " tip-bot for Kan Liang
2017-05-29 12:46 ` [PATCH V2 0/2] measure SMI cost (user) Jiri Olsa
2017-05-29 12:52 ` Peter Zijlstra
2017-05-29 13:16 ` Jiri Olsa
2017-05-29 17:06 ` Liang, Kan
2017-06-02 15:45 ` Liang, Kan
2017-06-02 18:27 ` Arnaldo Carvalho de Melo
2017-06-14 17:50 ` Liang, Kan
2017-06-20 13:43 ` Liang, Kan
2017-06-20 20:29 ` 'Arnaldo Carvalho de Melo'
2017-06-20 21:43 ` Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-3b00ea938653d136c8e4bcbe9722d954e128ce2e@git.kernel.org \
--to=tipbot@zytor.com \
--cc=acme@redhat.com \
--cc=ak@linux.intel.com \
--cc=elliott@hpe.com \
--cc=eranian@google.com \
--cc=hpa@zytor.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.