forked from luck/tmp_suning_uos_patched
20f2be1d48
We need the 'page_size' variable in libperf, so move it there. Add a libperf_init() as a global libperf init function to obtain this value via sysconf() at tool start. Committer notes: Add internal/lib.h to tools/perf/ files using 'page_size', sometimes replacing util.h with it if that was the only reason for having util.h included. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lore.kernel.org/lkml/20190913132355.21634-33-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
49 lines
902 B
C
49 lines
902 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <unistd.h>
|
|
#include <stdbool.h>
|
|
#include <errno.h>
|
|
#include <linux/kernel.h>
|
|
#include <internal/lib.h>
|
|
|
|
unsigned int page_size;
|
|
|
|
static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
|
|
{
|
|
void *buf_start = buf;
|
|
size_t left = n;
|
|
|
|
while (left) {
|
|
/* buf must be treated as const if !is_read. */
|
|
ssize_t ret = is_read ? read(fd, buf, left) :
|
|
write(fd, buf, left);
|
|
|
|
if (ret < 0 && errno == EINTR)
|
|
continue;
|
|
if (ret <= 0)
|
|
return ret;
|
|
|
|
left -= ret;
|
|
buf += ret;
|
|
}
|
|
|
|
BUG_ON((size_t)(buf - buf_start) != n);
|
|
return n;
|
|
}
|
|
|
|
/*
|
|
* Read exactly 'n' bytes or return an error.
|
|
*/
|
|
ssize_t readn(int fd, void *buf, size_t n)
|
|
{
|
|
return ion(true, fd, buf, n);
|
|
}
|
|
|
|
/*
|
|
* Write exactly 'n' bytes or return an error.
|
|
*/
|
|
ssize_t writen(int fd, const void *buf, size_t n)
|
|
{
|
|
/* ion does not modify buf. */
|
|
return ion(false, fd, (void *)buf, n);
|
|
}
|