xref: /aosp_15_r20/external/mesa3d/src/tool/pps/pps.cc (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2020 Collabora, Ltd.
3  * Author: Antonio Caggiano <[email protected]>
4  *
5  * SPDX-License-Identifier: MIT
6  */
7 
8 #include "pps.h"
9 
10 #include <cerrno>
11 #include <cstring>
12 
13 #include <sched.h>
14 
15 namespace pps
16 {
check(int res,const char * msg)17 bool check(int res, const char *msg)
18 {
19    if (res < 0) {
20       char *err_msg = std::strerror(errno);
21       PERFETTO_ELOG("%s: %s", msg, err_msg);
22       return false;
23    }
24 
25    return true;
26 }
27 
make_thread_rt()28 void make_thread_rt()
29 {
30    // Use FIFO policy to avoid preemption while collecting counters
31    int sched_policy = SCHED_FIFO;
32    // Do not use max priority to avoid starving migration and watchdog threads
33    int priority_value = sched_get_priority_max(sched_policy) - 1;
34    sched_param priority_param { priority_value };
35    sched_setscheduler(0, sched_policy, &priority_param);
36 }
37 
38 } // namespace pps
39