Commit 89e3bbd5 authored by Ingo Molnar's avatar Ingo Molnar

Merge tag 'perf-core-for-mingo' of...

Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core

Pull perf/tools improvements and fixes from Arnaldo Carvalho de Melo:

  * Honour -m option in 'trace', the tool was offering the option to
    set the mmap size, but wasn't using it when doing the actual mmap
    on the events file descriptors, fix from Jiri Olsa.

  * Correct the message in feature-libnuma checking, swowing the right
    devel package names for various distros, from Dongsheng Yang.

  * Polish 'readn' function and introduce its counterpart, 'writen', from
    Jiri Olsa.

  * Start moving timechart state from global variables to a 'perf_tool' derived
    'timechart' struct.
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parents 0ed1e0be f885037e
...@@ -76,7 +76,7 @@ struct perf_record { ...@@ -76,7 +76,7 @@ struct perf_record {
long samples; long samples;
}; };
static int do_write_output(struct perf_record *rec, void *buf, size_t size) static int perf_record__write(struct perf_record *rec, void *buf, size_t size)
{ {
struct perf_data_file *file = &rec->file; struct perf_data_file *file = &rec->file;
...@@ -97,21 +97,13 @@ static int do_write_output(struct perf_record *rec, void *buf, size_t size) ...@@ -97,21 +97,13 @@ static int do_write_output(struct perf_record *rec, void *buf, size_t size)
return 0; return 0;
} }
static int write_output(struct perf_record *rec, void *buf, size_t size)
{
return do_write_output(rec, buf, size);
}
static int process_synthesized_event(struct perf_tool *tool, static int process_synthesized_event(struct perf_tool *tool,
union perf_event *event, union perf_event *event,
struct perf_sample *sample __maybe_unused, struct perf_sample *sample __maybe_unused,
struct machine *machine __maybe_unused) struct machine *machine __maybe_unused)
{ {
struct perf_record *rec = container_of(tool, struct perf_record, tool); struct perf_record *rec = container_of(tool, struct perf_record, tool);
if (write_output(rec, event, event->header.size) < 0) return perf_record__write(rec, event, event->header.size);
return -1;
return 0;
} }
static int perf_record__mmap_read(struct perf_record *rec, static int perf_record__mmap_read(struct perf_record *rec,
...@@ -136,7 +128,7 @@ static int perf_record__mmap_read(struct perf_record *rec, ...@@ -136,7 +128,7 @@ static int perf_record__mmap_read(struct perf_record *rec,
size = md->mask + 1 - (old & md->mask); size = md->mask + 1 - (old & md->mask);
old += size; old += size;
if (write_output(rec, buf, size) < 0) { if (perf_record__write(rec, buf, size) < 0) {
rc = -1; rc = -1;
goto out; goto out;
} }
...@@ -146,7 +138,7 @@ static int perf_record__mmap_read(struct perf_record *rec, ...@@ -146,7 +138,7 @@ static int perf_record__mmap_read(struct perf_record *rec,
size = head - old; size = head - old;
old += size; old += size;
if (write_output(rec, buf, size) < 0) { if (perf_record__write(rec, buf, size) < 0) {
rc = -1; rc = -1;
goto out; goto out;
} }
...@@ -335,8 +327,8 @@ static int perf_record__mmap_read_all(struct perf_record *rec) ...@@ -335,8 +327,8 @@ static int perf_record__mmap_read_all(struct perf_record *rec)
} }
if (perf_header__has_feat(&rec->session->header, HEADER_TRACING_DATA)) if (perf_header__has_feat(&rec->session->header, HEADER_TRACING_DATA))
rc = write_output(rec, &finished_round_event, rc = perf_record__write(rec, &finished_round_event,
sizeof(finished_round_event)); sizeof(finished_round_event));
out: out:
return rc; return rc;
......
This diff is collapsed.
...@@ -1890,7 +1890,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) ...@@ -1890,7 +1890,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
if (err < 0) if (err < 0)
goto out_error_open; goto out_error_open;
err = perf_evlist__mmap(evlist, UINT_MAX, false); err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false);
if (err < 0) { if (err < 0) {
fprintf(trace->output, "Couldn't mmap the events: %s\n", strerror(errno)); fprintf(trace->output, "Couldn't mmap the events: %s\n", strerror(errno));
goto out_close_evlist; goto out_close_evlist;
......
...@@ -533,7 +533,7 @@ endif ...@@ -533,7 +533,7 @@ endif
ifndef NO_LIBNUMA ifndef NO_LIBNUMA
ifeq ($(feature-libnuma), 0) ifeq ($(feature-libnuma), 0)
msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numa-libs-devel or libnuma-dev); msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
NO_LIBNUMA := 1 NO_LIBNUMA := 1
else else
CFLAGS += -DHAVE_LIBNUMA_SUPPORT CFLAGS += -DHAVE_LIBNUMA_SUPPORT
......
...@@ -85,6 +85,10 @@ ...@@ -85,6 +85,10 @@
# include "test-timerfd.c" # include "test-timerfd.c"
#undef main #undef main
#define main main_test_stackprotector_all
# include "test-stackprotector-all.c"
#undef main
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
main_test_libpython(); main_test_libpython();
...@@ -106,6 +110,7 @@ int main(int argc, char *argv[]) ...@@ -106,6 +110,7 @@ int main(int argc, char *argv[])
main_test_backtrace(); main_test_backtrace();
main_test_libnuma(); main_test_libnuma();
main_test_timerfd(); main_test_timerfd();
main_test_stackprotector_all();
return 0; return 0;
} }
...@@ -118,3 +118,9 @@ void perf_data_file__close(struct perf_data_file *file) ...@@ -118,3 +118,9 @@ void perf_data_file__close(struct perf_data_file *file)
{ {
close(file->fd); close(file->fd);
} }
ssize_t perf_data_file__write(struct perf_data_file *file,
void *buf, size_t size)
{
return writen(file->fd, buf, size);
}
...@@ -9,12 +9,12 @@ enum perf_data_mode { ...@@ -9,12 +9,12 @@ enum perf_data_mode {
}; };
struct perf_data_file { struct perf_data_file {
const char *path; const char *path;
int fd; int fd;
bool is_pipe; bool is_pipe;
bool force; bool force;
unsigned long size; unsigned long size;
enum perf_data_mode mode; enum perf_data_mode mode;
}; };
static inline bool perf_data_file__is_read(struct perf_data_file *file) static inline bool perf_data_file__is_read(struct perf_data_file *file)
...@@ -44,5 +44,7 @@ static inline unsigned long perf_data_file__size(struct perf_data_file *file) ...@@ -44,5 +44,7 @@ static inline unsigned long perf_data_file__size(struct perf_data_file *file)
int perf_data_file__open(struct perf_data_file *file); int perf_data_file__open(struct perf_data_file *file);
void perf_data_file__close(struct perf_data_file *file); void perf_data_file__close(struct perf_data_file *file);
ssize_t perf_data_file__write(struct perf_data_file *file,
void *buf, size_t size);
#endif /* __PERF_DATA_H */ #endif /* __PERF_DATA_H */
...@@ -1709,7 +1709,7 @@ static int process_nrcpus(struct perf_file_section *section __maybe_unused, ...@@ -1709,7 +1709,7 @@ static int process_nrcpus(struct perf_file_section *section __maybe_unused,
struct perf_header *ph, int fd, struct perf_header *ph, int fd,
void *data __maybe_unused) void *data __maybe_unused)
{ {
size_t ret; ssize_t ret;
u32 nr; u32 nr;
ret = readn(fd, &nr, sizeof(nr)); ret = readn(fd, &nr, sizeof(nr));
...@@ -1753,7 +1753,7 @@ static int process_total_mem(struct perf_file_section *section __maybe_unused, ...@@ -1753,7 +1753,7 @@ static int process_total_mem(struct perf_file_section *section __maybe_unused,
void *data __maybe_unused) void *data __maybe_unused)
{ {
uint64_t mem; uint64_t mem;
size_t ret; ssize_t ret;
ret = readn(fd, &mem, sizeof(mem)); ret = readn(fd, &mem, sizeof(mem));
if (ret != sizeof(mem)) if (ret != sizeof(mem))
...@@ -1822,7 +1822,7 @@ static int process_cmdline(struct perf_file_section *section __maybe_unused, ...@@ -1822,7 +1822,7 @@ static int process_cmdline(struct perf_file_section *section __maybe_unused,
struct perf_header *ph, int fd, struct perf_header *ph, int fd,
void *data __maybe_unused) void *data __maybe_unused)
{ {
size_t ret; ssize_t ret;
char *str; char *str;
u32 nr, i; u32 nr, i;
struct strbuf sb; struct strbuf sb;
...@@ -1858,7 +1858,7 @@ static int process_cpu_topology(struct perf_file_section *section __maybe_unused ...@@ -1858,7 +1858,7 @@ static int process_cpu_topology(struct perf_file_section *section __maybe_unused
struct perf_header *ph, int fd, struct perf_header *ph, int fd,
void *data __maybe_unused) void *data __maybe_unused)
{ {
size_t ret; ssize_t ret;
u32 nr, i; u32 nr, i;
char *str; char *str;
struct strbuf sb; struct strbuf sb;
...@@ -1914,7 +1914,7 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse ...@@ -1914,7 +1914,7 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse
struct perf_header *ph, int fd, struct perf_header *ph, int fd,
void *data __maybe_unused) void *data __maybe_unused)
{ {
size_t ret; ssize_t ret;
u32 nr, node, i; u32 nr, node, i;
char *str; char *str;
uint64_t mem_total, mem_free; uint64_t mem_total, mem_free;
...@@ -1974,7 +1974,7 @@ static int process_pmu_mappings(struct perf_file_section *section __maybe_unused ...@@ -1974,7 +1974,7 @@ static int process_pmu_mappings(struct perf_file_section *section __maybe_unused
struct perf_header *ph, int fd, struct perf_header *ph, int fd,
void *data __maybe_unused) void *data __maybe_unused)
{ {
size_t ret; ssize_t ret;
char *name; char *name;
u32 pmu_num; u32 pmu_num;
u32 type; u32 type;
...@@ -2534,7 +2534,7 @@ static int check_magic_endian(u64 magic, uint64_t hdr_sz, ...@@ -2534,7 +2534,7 @@ static int check_magic_endian(u64 magic, uint64_t hdr_sz,
int perf_file_header__read(struct perf_file_header *header, int perf_file_header__read(struct perf_file_header *header,
struct perf_header *ph, int fd) struct perf_header *ph, int fd)
{ {
int ret; ssize_t ret;
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
...@@ -2628,7 +2628,7 @@ static int perf_file_header__read_pipe(struct perf_pipe_file_header *header, ...@@ -2628,7 +2628,7 @@ static int perf_file_header__read_pipe(struct perf_pipe_file_header *header,
struct perf_header *ph, int fd, struct perf_header *ph, int fd,
bool repipe) bool repipe)
{ {
int ret; ssize_t ret;
ret = readn(fd, header, sizeof(*header)); ret = readn(fd, header, sizeof(*header));
if (ret <= 0) if (ret <= 0)
...@@ -2669,7 +2669,7 @@ static int read_attr(int fd, struct perf_header *ph, ...@@ -2669,7 +2669,7 @@ static int read_attr(int fd, struct perf_header *ph,
struct perf_event_attr *attr = &f_attr->attr; struct perf_event_attr *attr = &f_attr->attr;
size_t sz, left; size_t sz, left;
size_t our_sz = sizeof(f_attr->attr); size_t our_sz = sizeof(f_attr->attr);
int ret; ssize_t ret;
memset(f_attr, 0, sizeof(*f_attr)); memset(f_attr, 0, sizeof(*f_attr));
......
...@@ -1158,7 +1158,7 @@ static int __perf_session__process_pipe_events(struct perf_session *session, ...@@ -1158,7 +1158,7 @@ static int __perf_session__process_pipe_events(struct perf_session *session,
void *buf = NULL; void *buf = NULL;
int skip = 0; int skip = 0;
u64 head; u64 head;
int err; ssize_t err;
void *p; void *p;
perf_tool__fill_defaults(tool); perf_tool__fill_defaults(tool);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <linux/kernel.h>
/* /*
* XXX We need to find a better place for these things... * XXX We need to find a better place for these things...
...@@ -151,21 +152,40 @@ unsigned long convert_unit(unsigned long value, char *unit) ...@@ -151,21 +152,40 @@ unsigned long convert_unit(unsigned long value, char *unit)
return value; return value;
} }
int readn(int fd, void *buf, size_t n) static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
{ {
void *buf_start = buf; void *buf_start = buf;
size_t left = n;
while (n) { while (left) {
int ret = read(fd, buf, n); ssize_t ret = is_read ? read(fd, buf, left) :
write(fd, buf, left);
if (ret <= 0) if (ret <= 0)
return ret; return ret;
n -= ret; left -= ret;
buf += ret; buf += ret;
} }
return buf - buf_start; 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, void *buf, size_t n)
{
return ion(false, fd, buf, n);
} }
size_t hex_width(u64 v) size_t hex_width(u64 v)
......
...@@ -253,7 +253,8 @@ bool strlazymatch(const char *str, const char *pat); ...@@ -253,7 +253,8 @@ bool strlazymatch(const char *str, const char *pat);
int strtailcmp(const char *s1, const char *s2); int strtailcmp(const char *s1, const char *s2);
char *strxfrchar(char *s, char from, char to); char *strxfrchar(char *s, char from, char to);
unsigned long convert_unit(unsigned long value, char *unit); unsigned long convert_unit(unsigned long value, char *unit);
int readn(int fd, void *buf, size_t size); ssize_t readn(int fd, void *buf, size_t n);
ssize_t writen(int fd, void *buf, size_t n);
struct perf_event_attr; struct perf_event_attr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment