Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions simple-pt.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ static struct kernel_param_ops trace_stop_ops = {
/* Support for Linux panic dumps (optional) */

static int pt_num_buffers = 1;

static int get_topa_order(void)
{
return get_order((pt_num_buffers + 1) * 8);
}

static int log_dump = 0;
static void print_last_branches(int num_psbs);

Expand Down Expand Up @@ -674,7 +680,7 @@ static int simple_pt_buffer_init(int cpu)
if (!topa) {
int n;

topa = (u64 *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
topa = (u64 *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, get_topa_order());
if (!topa) {
pr_err("cpu %d, Cannot allocate topa page\n", cpu);
goto out_pt_buffer;
Expand Down Expand Up @@ -801,12 +807,12 @@ static long simple_pt_ioctl(struct file *file, unsigned int cmd,
return 0;
}
case SIMPLE_PT_GET_SIZE: {
int num = topa_entries(file_get_cpu(file));
u64 num = topa_entries(file_get_cpu(file));
return put_user(num * (PAGE_SIZE << pt_buffer_order),
(int *)arg);
(u64 *)arg);
}
case SIMPLE_PT_GET_OFFSET: {
unsigned offset;
u64 offset;
int ret = 0;
mutex_lock(&restart_mutex);
if (per_cpu(pt_running, file_get_cpu(file)))
Expand All @@ -815,7 +821,7 @@ static long simple_pt_ioctl(struct file *file, unsigned int cmd,
offset = per_cpu(pt_offset, file_get_cpu(file));
mutex_unlock(&restart_mutex);
if (!ret)
ret = put_user(offset, (int *)arg);
ret = put_user(offset, (u64 *)arg);
return ret;
}
default:
Expand Down Expand Up @@ -1094,8 +1100,7 @@ static int simple_pt_cpuid(void)
addr_cfg_max = 2;
if (!(c & BIT(1)))
pt_num_buffers = 1;
pt_num_buffers = min_t(unsigned, pt_num_buffers,
(PAGE_SIZE / 8) - 1);

a1 = b1 = c1 = d1 = 0;
if (a >= 1)
cpuid_count(0x14, 1, &a1, &b1, &c1, &d1);
Expand Down Expand Up @@ -1137,7 +1142,7 @@ static int spt_cpu_teardown(unsigned int cpu)
if (per_cpu(topa_cpu, cpu)) {
u64 *topa = per_cpu(topa_cpu, cpu);
free_topa(topa);
free_page((unsigned long)topa);
free_pages((unsigned long)topa, get_topa_order());
per_cpu(topa_cpu, cpu) = NULL;
}
if (per_cpu(pt_buffer_cpu, cpu)) {
Expand Down
29 changes: 23 additions & 6 deletions sptdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sys/mman.h>
#include <signal.h>
#include <sys/ioctl.h>
Expand All @@ -45,11 +46,26 @@

#define err(x) perror(x), exit(1)

size_t write_all(int fd, char *buf, size_t sz)
{
size_t left = sz;
while(left) {
size_t once = 1UL * 1024 * 1024 * 1024;
once = once > left ? left : once;
ssize_t ret = write(fd, buf, once);
if (ret <= 0)
err("write to file");
left -= ret;
buf += ret;
}
return sz;
}

int main(int ac, char **av)
{
int ncpus = sysconf(_SC_NPROCESSORS_CONF);
int pfds[ncpus];
int bufsize;
uint64_t bufsize;
char *pbuf[ncpus];

int i;
Expand Down Expand Up @@ -79,17 +95,18 @@ int main(int ac, char **av)
if (fd < 0)
err("Opening output file");

unsigned offset;
uint64_t offset;
if (ioctl(pfds[i], SIMPLE_PT_GET_OFFSET, &offset) < 0) {
perror("SIMPLE_PT_GET_OFFSET");
continue;
}

unsigned len = 0;
size_t len = 0;
if (*(uint64_t *)(pbuf[i] + offset))
len += write(fd, pbuf[i] + offset, bufsize - offset);
len += write(fd, pbuf[i], offset);
printf("cpu %3d offset %6u, %5u KB, writing to %s\n", i, offset, len >> 10, fn);
len += write_all(fd, pbuf[i] + offset, bufsize - offset);
len += write_all(fd, pbuf[i], offset);
printf("cpu %3d offset %6" PRIu64 ", %5zu KB, writing to %s\n", i, offset, len >> 10, fn);

close(fd);
if (len == 0)
unlink(fn);
Expand Down