Skip to content

Commit

Permalink
Add a cli option to force /dev/mem
Browse files Browse the repository at this point in the history
  • Loading branch information
clbr committed Nov 11, 2015
1 parent f4f2889 commit 2c97b97
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
7 changes: 6 additions & 1 deletion detect.c
Expand Up @@ -83,7 +83,7 @@ static void finddrm(const unsigned char bus) {
free(namelist);
}

unsigned int init_pci(unsigned char bus) {
unsigned int init_pci(unsigned char bus, const unsigned char forcemem) {

int ret = pci_system_init();
if (ret)
Expand Down Expand Up @@ -138,6 +138,11 @@ unsigned int init_pci(unsigned char bus) {
use_ioctl = get_drm_value(drm_fd, RADEON_INFO_READ_REG, &rreg);
}

if (forcemem) {
printf(_("Forcing the /dev/mem path.\n"));
use_ioctl = 0;
}

if (!use_ioctl) {
int mem = open("/dev/mem", O_RDONLY);
if (mem < 0) die(_("Cannot access GPU registers, are you root?"));
Expand Down
2 changes: 1 addition & 1 deletion include/radeontop.h
Expand Up @@ -57,7 +57,7 @@ extern const void *area;
extern int use_ioctl;

// detect.c
unsigned int init_pci(unsigned char bus);
unsigned int init_pci(unsigned char bus, const unsigned char forcemem);
int getfamily(unsigned int id);
void initbits(int fam);
unsigned long long getvram();
Expand Down
9 changes: 7 additions & 2 deletions radeontop.1
Expand Up @@ -2,12 +2,12 @@
.\" Title: radeontop
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\" Date: 06/24/2015
.\" Date: 11/11/2015
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "RADEONTOP" "1" "06/24/2015" "\ \&" "\ \&"
.TH "RADEONTOP" "1" "11/11/2015" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -81,6 +81,11 @@ or
for graceful termination\&.
.RE
.PP
\fB\-m, \-\-mem\fR
.RS 4
Forces the use of the /dev/mem path, in case autodetection fails\&. Useful for the proprietary driver\&.
.RE
.PP
\fB\-t, \-\-ticks \fR\fB\fIticks\fR\fR
.RS 4
How many times per second to sample the data\&. The default is 120\&. Higher numbers mean more accurate output and more overhead\&.
Expand Down
4 changes: 4 additions & 0 deletions radeontop.asc
Expand Up @@ -38,6 +38,10 @@ OPTIONS
Quit after dumping 'limit' lines. Only valid in dump mode. Default is
to dump until terminated; use 'SIGTERM' or 'SIGINT' for graceful termination.

*-m, --mem*::
Forces the use of the /dev/mem path, in case autodetection fails.
Useful for the proprietary driver.

*-t, --ticks 'ticks'*::
How many times per second to sample the data. The default is 120.
Higher numbers mean more accurate output and more overhead.
Expand Down
11 changes: 8 additions & 3 deletions radeontop.c
Expand Up @@ -37,6 +37,7 @@ static void help(const char * const me, const unsigned int ticks) {
"-c --color Enable colors\n"
"-d --dump file Dump data to this file, - for stdout\n"
"-l --limit 3 Quit after dumping N lines, default forever\n"
"-m --mem Force the /dev/mem path, for the proprietary driver\n"
"-t --ticks 50 Samples per second (default %u)\n"
"\n"
"-h --help Show this help\n"
Expand Down Expand Up @@ -75,7 +76,7 @@ int main(int argc, char **argv) {

unsigned int ticks = 120;
unsigned char color = 0;
unsigned char bus = 0;
unsigned char bus = 0, forcemem = 0;
unsigned int limit = 0;
char *dump = NULL;

Expand All @@ -93,13 +94,14 @@ int main(int argc, char **argv) {
{"dump", 1, 0, 'd'},
{"help", 0, 0, 'h'},
{"limit", 1, 0, 'l'},
{"mem", 0, 0, 'm'},
{"ticks", 1, 0, 't'},
{"version", 0, 0, 'v'},
{0, 0, 0, 0}
};

while (1) {
int c = getopt_long(argc, argv, "b:cd:hl:t:v", opts, NULL);
int c = getopt_long(argc, argv, "b:cd:hl:mt:v", opts, NULL);
if (c == -1) break;

switch(c) {
Expand All @@ -113,6 +115,9 @@ int main(int argc, char **argv) {
case 'c':
color = 1;
break;
case 'm':
forcemem = 1;
break;
case 'b':
bus = atoi(optarg);
break;
Expand All @@ -129,7 +134,7 @@ int main(int argc, char **argv) {
}

// init
const unsigned int pciaddr = init_pci(bus);
const unsigned int pciaddr = init_pci(bus, forcemem);

const int family = getfamily(pciaddr);
if (!family)
Expand Down

0 comments on commit 2c97b97

Please sign in to comment.