Statistics
| Branch: | Tag: | Revision:

root / host / lib / sched.cpp @ ca641773

History | View | Annotate | Download (1.43 KB)

1
//
2
// Copyright 2010 Ettus Research LLC
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
//
17

    
18
#include <uhd/utils/static.hpp>
19
#include <stdexcept>
20
#include <iostream>
21

    
22
#ifdef HAVE_SCHED_H
23
#include <sched.h>
24

    
25
/*
26
 * # /etc/security/limits.conf
27
#
28
@usrp   -       rtprio  99
29
*/
30

    
31
UHD_STATIC_BLOCK(setup_process_sched){
32
    try{
33
        int policy = SCHED_RR;
34
        int max_pri = sched_get_priority_max(policy);
35
        if (max_pri == -1) throw std::runtime_error("sched_get_priority_max with SCHED_RR failed");
36
        sched_param sp; sp.sched_priority = max_pri;
37
        int ss_ret = sched_setscheduler(0, policy, &sp);
38
        if (ss_ret == -1) throw std::runtime_error("sched_setscheduler with SCHED_RR failed");
39
    }
40
    catch(const std::exception &e){
41
        std::cerr << "Process scheduling error: " << e.what() << std::endl;
42
    }
43
}
44

    
45
#endif /* HAVE_SCHED_H */