line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Linux::IO_Prio; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
43380
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
74
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
73
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
2
|
|
|
2
|
|
10
|
use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS $VERSION); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
171
|
|
8
|
2
|
|
|
2
|
|
2053
|
use POSIX qw(ENOSYS); |
|
2
|
|
|
|
|
14047
|
|
|
2
|
|
|
|
|
15
|
|
9
|
2
|
|
|
2
|
|
2349
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
358
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.03'; |
12
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
%EXPORT_TAGS = (ionice => [qw(&ionice &ionice_class &ionice_data)], |
14
|
|
|
|
|
|
|
c_api => [qw(&ioprio_set &ioprio_get)], |
15
|
|
|
|
|
|
|
macros => [qw(IOPRIO_PRIO_VALUE IOPRIO_PRIO_CLASS IOPRIO_PRIO_DATA)], |
16
|
|
|
|
|
|
|
who => [qw(IOPRIO_WHO_PROCESS IOPRIO_WHO_PGRP IOPRIO_WHO_USE)], |
17
|
|
|
|
|
|
|
class => [qw(IOPRIO_CLASS_NONE IOPRIO_CLASS_RT IOPRIO_CLASS_BE IOPRIO_CLASS_IDLE)] |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
# The tag lists are exclusive at the moment, so don't worry about duplicates. |
20
|
|
|
|
|
|
|
push @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} foreach keys %EXPORT_TAGS; |
21
|
|
|
|
|
|
|
Exporter::export_ok_tags($_) foreach keys %EXPORT_TAGS; |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
13
|
use constant IOPRIO_CLASS_SHIFT => 13; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
338
|
|
24
|
2
|
|
|
2
|
|
12
|
use constant IOPRIO_PRIO_MASK => ((1 << IOPRIO_CLASS_SHIFT) - 1); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
109
|
|
25
|
|
|
|
|
|
|
use constant { |
26
|
2
|
|
|
|
|
224
|
IOPRIO_WHO_PROCESS => 1, |
27
|
|
|
|
|
|
|
IOPRIO_WHO_PGRP => 2, |
28
|
|
|
|
|
|
|
IOPRIO_WHO_USER => 3 |
29
|
2
|
|
|
2
|
|
11
|
}; |
|
2
|
|
|
|
|
3
|
|
30
|
|
|
|
|
|
|
use constant { |
31
|
2
|
|
|
|
|
1241
|
IOPRIO_CLASS_NONE => 0, |
32
|
|
|
|
|
|
|
IOPRIO_CLASS_RT => 1, |
33
|
|
|
|
|
|
|
IOPRIO_CLASS_BE => 2, |
34
|
|
|
|
|
|
|
IOPRIO_CLASS_IDLE => 3 |
35
|
2
|
|
|
2
|
|
11
|
}; |
|
2
|
|
|
|
|
2
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
if ($^O eq 'linux') { |
38
|
|
|
|
|
|
|
_load_syscall(); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
|
|
|
|
|
|
warn "Linux::IO_Prio: unsupported operating system -- $^O\n"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Load syscall.ph |
45
|
|
|
|
|
|
|
sub _load_syscall { |
46
|
3
|
0
|
|
3
|
|
13
|
return eval{require('syscall.ph') || require('sys/syscall.ph')}; |
|
3
|
|
|
|
|
709
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# C API functions |
50
|
|
|
|
|
|
|
# int ioprio_get(int which, int who); |
51
|
|
|
|
|
|
|
sub ioprio_get { |
52
|
3
|
|
|
3
|
1
|
6
|
my ($which, $who) = @_; |
53
|
3
|
50
|
|
|
|
8
|
if (defined &SYS_ioprio_get) { |
54
|
0
|
|
|
|
|
0
|
return syscall(SYS_ioprio_get(), $which, $who); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
3
|
|
|
|
|
8
|
return _not_implemented(); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# int ioprio_set(int which, int who, int ioprio); |
62
|
|
|
|
|
|
|
sub ioprio_set { |
63
|
2
|
|
|
2
|
1
|
6
|
my ($which, $who, $ioprio) = @_; |
64
|
2
|
50
|
|
|
|
7
|
if (defined &SYS_ioprio_set) { |
65
|
0
|
|
|
|
|
0
|
return syscall(SYS_ioprio_set(), $which, $who, $ioprio); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
2
|
|
|
|
|
6
|
return _not_implemented(); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# C API Macros |
73
|
|
|
|
|
|
|
sub IOPRIO_PRIO_VALUE { |
74
|
2
|
|
|
2
|
1
|
611
|
my ($class, $data) = @_; |
75
|
2
|
|
|
|
|
12
|
return ($class << IOPRIO_CLASS_SHIFT) | $data; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub IOPRIO_PRIO_CLASS { |
79
|
0
|
|
|
0
|
1
|
0
|
my ($mask) = @_; |
80
|
0
|
|
|
|
|
0
|
return ($mask >> IOPRIO_CLASS_SHIFT); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub IOPRIO_PRIO_DATA { |
84
|
0
|
|
|
0
|
1
|
0
|
my ($mask) = @_; |
85
|
0
|
|
|
|
|
0
|
return ($mask & IOPRIO_PRIO_MASK); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Wrapper functions |
89
|
|
|
|
|
|
|
sub ionice { |
90
|
1
|
|
|
1
|
1
|
4
|
my ($which, $who, $class, $data) = @_; |
91
|
1
|
50
|
33
|
|
|
11
|
carp "Data not permitted for class IOPRIO_CLASS_IDLE" if $class == IOPRIO_CLASS_IDLE && $data; |
92
|
1
|
|
|
|
|
3
|
return ioprio_set($which, $who, IOPRIO_PRIO_VALUE($class, $data)); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub ionice_class { |
96
|
1
|
|
|
1
|
1
|
5
|
my ($which, $who) = @_; |
97
|
1
|
50
|
|
|
|
4
|
if((my $priority = ioprio_get($which, $who)) < 0) { |
98
|
1
|
|
|
|
|
5
|
return $priority; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
0
|
|
|
|
|
0
|
return IOPRIO_PRIO_CLASS($priority); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub ionice_data { |
106
|
1
|
|
|
1
|
1
|
3
|
my ($which, $who) = @_; |
107
|
1
|
50
|
|
|
|
3
|
if((my $priority = ioprio_get($which, $who)) < 0) { |
108
|
1
|
|
|
|
|
5
|
return $priority; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else { |
111
|
0
|
|
|
|
|
0
|
return IOPRIO_PRIO_DATA($priority); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Stub for not implemented |
116
|
|
|
|
|
|
|
sub _not_implemented { |
117
|
5
|
|
|
5
|
|
11
|
$! = ENOSYS; |
118
|
5
|
|
|
|
|
27
|
return -1; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
__END__ |