Skip to content

Commit

Permalink
Allow unprivileged use of radeontop via console
Browse files Browse the repository at this point in the history
With appropriate privileges on the /dev/dri/cardN files, it is possible
to run radeontop as normal user. At minimum you need read/write
permissions:

    sudo setfacl -m u:$USER:rw /dev/dri/card*

You also need to be the DRM Master (i.e. Xorg must not be active on a
console).
  • Loading branch information
Lekensteyn authored and clbr committed Jul 4, 2016
1 parent 761ffe2 commit fc51270
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@ RadeonTop

View your GPU utilization, both for the total activity percent and individual blocks.

Requires root rights or other permissions to /dev/mem.
Requires access to /dev/dri/cardN files or /dev/mem (root privileges).

Supported cards
---------------
Expand Down
31 changes: 31 additions & 0 deletions auth.c
@@ -0,0 +1,31 @@
/*
Copyright (C) 2016 Peter Wu <peter@lekensteyn.nl>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "radeontop.h"

void authenticate_drm(int fd) {
drm_magic_t magic;

/* Obtain magic for our DRM client. */
if (drmGetMagic(fd, &magic) < 0) {
return;
}

/* Try self-authenticate (if we are somehow the master). */
if (drmAuthMagic(fd, magic) == 0) {
return;
}
}
1 change: 1 addition & 0 deletions detect.c
Expand Up @@ -135,6 +135,7 @@ unsigned int init_pci(unsigned char bus, const unsigned char forcemem) {

use_ioctl = 0;
if (drm_fd >= 0) {
authenticate_drm(drm_fd);
uint32_t rreg = 0x8010;
use_ioctl = get_drm_value(drm_fd, RADEON_INFO_READ_REG, &rreg);
}
Expand Down
3 changes: 3 additions & 0 deletions include/radeontop.h
Expand Up @@ -48,6 +48,9 @@ enum {
#define RADEON_INFO_READ_REG 0x24
#endif

// auth.c
void authenticate_drm(int fd);

// radeontop.c
void die(const char *why);
int get_drm_value(int fd, unsigned request, uint32_t *out);
Expand Down

0 comments on commit fc51270

Please sign in to comment.