mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-22 12:14:01 +08:00
libperf: Adopt the readn()/writen() functions from tools/perf
Move the readn()/writen() functions into libperf. Keep those non-namespaced names because they will be shared only between perf and libperf. Again, these are not exported functions. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexey Budankov <alexey.budankov@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20190721112506.12306-61-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
5643b1a59e
commit
c03538b1f1
@ -5,6 +5,7 @@ libperf-y += evsel.o
|
|||||||
libperf-y += evlist.o
|
libperf-y += evlist.o
|
||||||
libperf-y += zalloc.o
|
libperf-y += zalloc.o
|
||||||
libperf-y += xyarray.o
|
libperf-y += xyarray.o
|
||||||
|
libperf-y += lib.o
|
||||||
|
|
||||||
$(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE
|
$(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE
|
||||||
$(call rule_mkdir)
|
$(call rule_mkdir)
|
||||||
|
10
tools/perf/lib/include/internal/lib.h
Normal file
10
tools/perf/lib/include/internal/lib.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0 */
|
||||||
|
#ifndef __LIBPERF_INTERNAL_LIB_H
|
||||||
|
#define __LIBPERF_INTERNAL_LIB_H
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
ssize_t readn(int fd, void *buf, size_t n);
|
||||||
|
ssize_t writen(int fd, const void *buf, size_t n);
|
||||||
|
|
||||||
|
#endif /* __LIBPERF_INTERNAL_CPUMAP_H */
|
46
tools/perf/lib/lib.c
Normal file
46
tools/perf/lib/lib.c
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <linux/kernel.h>
|
||||||
|
#include <internal/lib.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
@ -384,46 +384,6 @@ int copyfile(const char *from, const char *to)
|
|||||||
return copyfile_mode(from, to, 0755);
|
return copyfile_mode(from, to, 0755);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t hex_width(u64 v)
|
size_t hex_width(u64 v)
|
||||||
{
|
{
|
||||||
size_t n = 1;
|
size_t n = 1;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <linux/compiler.h>
|
#include <linux/compiler.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <internal/lib.h>
|
||||||
|
|
||||||
/* General helper functions */
|
/* General helper functions */
|
||||||
void usage(const char *err) __noreturn;
|
void usage(const char *err) __noreturn;
|
||||||
@ -30,9 +31,6 @@ int copyfile_mode(const char *from, const char *to, mode_t mode);
|
|||||||
int copyfile_ns(const char *from, const char *to, struct nsinfo *nsi);
|
int copyfile_ns(const char *from, const char *to, struct nsinfo *nsi);
|
||||||
int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size);
|
int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size);
|
||||||
|
|
||||||
ssize_t readn(int fd, void *buf, size_t n);
|
|
||||||
ssize_t writen(int fd, const void *buf, size_t n);
|
|
||||||
|
|
||||||
size_t hex_width(u64 v);
|
size_t hex_width(u64 v);
|
||||||
|
|
||||||
extern unsigned int page_size;
|
extern unsigned int page_size;
|
||||||
|
Loading…
Reference in New Issue
Block a user