File: FreeBSDNvidiaGpu.cpp

package info (click to toggle)
ksystemstats 6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,528 kB
  • sloc: cpp: 4,881; makefile: 6; sh: 1
file content (29 lines) | stat: -rw-r--r-- 1,016 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * SPDX-FileCopyrightText: 2024 Henry Hu <henry.hu.sh@gmail.com>
 *
 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
 */

#include "FreeBSDNvidiaGpu.h"

#include <QRegularExpression>

#include "debug.h"

// FreeBSD's devinfo returns locations like "slot=0 function=0 dbsf=pci0:1:0:0 ...",
// we need to convert it to the format exported by nvidia-smi, like "0000:01:00.0".
QString convertLocationToPciPath(const QString& location) {
    QRegularExpression re("dbsf=pci(\\d+):(\\d+):(\\d+):(\\d+)");
    QRegularExpressionMatch match = re.match(location);
    if (!match.hasMatch()) {
        return "";
    }
    return QString::asprintf("%04x:%02x:%02x.%x", match.captured(1).toInt(), match.captured(2).toInt(), match.captured(3).toInt(), match.captured(4).toInt());
}

FreeBSDNvidiaGpu::FreeBSDNvidiaGpu(const QString &id, const QString &name, const QString &location)
    : NvidiaGpu(id, name, convertLocationToPciPath(location))
{
}

#include "moc_FreeBSDNvidiaGpu.cpp"