Whamcloud - gitweb
LU-17705 ptlrpc: replace synchronize_rcu() with rcu_barrier()
[fs/lustre-release.git] / contrib / debug_tools / epython_scripts / crashlib / cid / page_flags.py
1
2 """
3 Provide access to the page flags known by crash.
4 Copyright 2014 Cray Inc.  All Rights Reserved
5
6 The data is gathered from the 'kmem -g' command.
7 """
8
9 from pykdump.API import *
10
11 import crashlib.cid
12
13
14 class PageFlag:
15     # Note: This class should probably be abstracted somewhere as a
16     # bit or bitmask class, but since we don't have that yet, just
17     # create a new class here.
18     """Represent a flag as a bit mask and a shift value."""
19     def __init__(self, name, shift_val):
20         self.name  = name
21         self.shift = int(shift_val)
22         self.mask  = 1 << self.shift
23
24     def __call__(self):
25         return self.mask
26
27
28 class MachPageFlags:
29     """Extract the machine-specific page flags from crash.
30
31     When instantiated, this class produces an object with data members
32     for each kernel page flag that crash knows about, based on the kernel
33     version.  Each page flag is an instance of class PageFlag.  An example
34     of usage would be:
35
36         page = readSU('struct page', page_addr)
37         kpf = MachPageFlags()
38         if page.flags & kpf.PG_slab.mask:
39             ...
40     """
41
42     def __init__(self):
43         """Extract the page flags from the crash 'kmem -g' command."""
44         for line in exec_crash_command('kmem -g').splitlines():
45             # crash> kmem -g
46             # PAGE-FLAG       BIT  VALUE
47             # PG_locked         0  0000001
48             # PG_waiters        1  0000002
49             # ...
50             fields = line.split()
51             if len(fields) < 3 or fields[0][0:3] != 'PG_': continue
52
53             name  = fields[0]
54             shift = int(fields[1])
55             self.__dict__[name] = PageFlag(name, shift)
56
57 # --------------------------------------------------------------------------
58
59 # Create a shared instances of the above classes.
60
61 crashlib.cid.pgflags = MachPageFlags()