All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/18] RAS daemon: Easter Eggs Edition
@ 2011-04-23 16:28 Borislav Petkov
  2011-04-23 16:28 ` [PATCH 01/18] perf: Start the restructuring Borislav Petkov
                   ` (18 more replies)
  0 siblings, 19 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Ok, here's yet another version of the RAS daemon patchset. This one
changes all the event handling to how it is done in test__basic_mmap(),
as acme suggested. Patchset is against tip/perf/core from today.

With this I can inject an mce using the python script below (yeah, work
in progress in itself):

$ mcegen.py -i sw

	[ this will inject a random MCE using the mce_amd_inj.ko module ]

and in /var/log/ras.log I get:

MCE on cpu 0, status: 0xf200210000000853, addr: 0x0000000000000000
MCE on cpu 0, status: 0x9800400000000015, addr: 0x0000000000000000
MCE on cpu 0, status: 0xfc00200000050e0f, addr: 0x0000000000000000
MCE on cpu 0, status: 0x98004100001c010b, addr: 0x0000000000000000
MCE on cpu 0, status: 0xbc00200000000843, addr: 0x0000000000000000
MCE on cpu 0, status: 0xda00410000080e0f, addr: 0x0000000000000000

Yep, it is still raw info but you can do almost anything with that info
in userspace.

Next on the TODO list is changing the tracepoint to convey the decoded
info too which should be a fairly simple task to do.

So we've got the basic design hammered out methinks, the persistent
event is off by default for now and since rebasing this pile is always a
great PITA for me due to other developments in tools/perf, I'd like it
very much if I could offload it in -tip soon.

Also, last time there was a concern raised in the LWN article on the RAS
daemon that the library split is kinda questionable. Well, the argument
I use was the specific topic each piece of the code belongs to:

lib/lk/ is generic stuff which could very well be used by other tools in
the growing tools/ directory (hurray!).

lib/trace/ is the trace event parsing stuff from Steven

lib/perf/ is all the perf-related functionality that other tools might
use too when they need perf events, like this very same RAS daemon does.

Also, the expectation is that trace and perf should merge some day (for
arbitrary meaning of "some day" :)).

Also, I've exported only the stuff I need for the daemon and not
everything, like acme suggested at the time.

Anyway, I'm open to all suggestions and comments, as always.

Thanks.

--
#!/usr/bin/python

import os
import sys
import struct
import inspect
import subprocess
from random import *
from optparse import OptionParser

eecs = ['ECC/Resv', 'CRC', 'Sync', 'Mst Abort', 'Tgt Abort',                         #0-4
        'GART', 'RMW', 'WDT', 'ECC', 'DEV', 'Link Data',                             #5-10
        'Protocol', 'NB Array', 'DRAM Parity', 'Link Retry',                         #11-14
        'GART/DEV Table Walk', 'Resv', 'Resv', 'Resv', 'Resv', 'Resv',               #15-20
        'Resv', 'Resv', 'Resv', 'Resv', 'Resv', 'Resv',                              #21-26
        'Resv', 'L3 Cache Data', 'L3 Cache Tag', 'L3 Cache LRU', 'Probe Filter']     #27-31

r4s = ['GEN', 'RD', 'WR', 'DRD', 'DWR', 'IRD', 'PRF', 'EV', 'SNP']
lls = ['RESV', 'L1', 'L2', 'LG' ]
iis = ['MEM', 'RESV', 'IO', 'GEN' ]
tts = ['INSN', 'DATA', 'GEN', 'RESV' ]
pps = ['SRC', 'RES', 'OBS', 'GEN' ]

fus = {'DC': 0, 'IC': 1, 'BU': 2, 'CU': 2, 'LS': 3, 'NB': 4, 'FR': 5, 'EX': 5, 'FP': 6}
error_types = ['TLB', 'MEM', 'BUS']

families = ['k8', 'f10h', 'f11h', 'f12h', 'f14h', 'f15h']

# MSRs
MSR_K7_HWCR = 0xc0010015

MSR_IA32_MC0_CTL    = 0x00000400
MSR_IA32_MC0_STATUS = 0x00000401
MSR_IA32_MC0_ADDR   = 0x00000402
MSR_IA32_MC0_MISC   = 0x00000403

def MSR_IA32_MCx_CTL(x):        return MSR_IA32_MC0_CTL + 4*x
def MSR_IA32_MCx_STATUS(x):     return MSR_IA32_MC0_STATUS + 4*x
def MSR_IA32_MCx_ADDR(x):       return MSR_IA32_MC0_ADDR + 4*x
def MSR_IA32_MCx_MISC(x):       return MSR_IA32_MC0_MISC + 4*x


def __func__(lvl=1):
    return inspect.stack()[lvl][3]

def err(s):
    sys.stderr.write(("%s: Error %s\n" % (__func__(2), s)))

def dbg(s):
    if opts.dbg:
        sys.stderr.write(("%s: %s\n" % (__func__(2), s)))

def bit(b):
    if b < 0 or b > 63:
        return 0
    return 1L << b

class MCE(object):
    """ Class representing a Machine Check Exception signature
    """

    mci_status  = 0
    syndrome    = 0
    fu          = 'DC'  # DC MCE by default
    err_type    = 'BUS'

    def __init__(self, val=0, fu='DC', err_type='BUS'):
        self.err_type = err_type
        self.fu = fu

        if val:
            self.mci_status = val
        else:
            self.gen_mce()


    def eec(self, mce=None):
        if mce:
            return (mce >> 16) & 0x1f

        return (self.mci_status >> 16) & 0x1f

    def __is_ecc(self, mce=None):
        return self.eec(mce) == 0x8

    def _sanitize_error_type(self, mce):
        ec = mce & 0xffff

        # TLB
        if ec & bit(4):
            mce &= 0xffffffffffff001f
        # MEM
        elif ec & bit(8):
            mce &= 0xffffffffffff01ffL
            # RRRR is max 8
            if mce & bit(7):
                mce &= ~(0x7 << 4)
        # BUS
        elif ec & bit(11):
            mce &= 0xffffffffffff0fffL
            # RRRR is max 8
            if mce & bit(7):
                mce &= ~(0x7 << 4)

        else:
            # fallback to a BUS error (those are most common: DRAM ECC)
            mce &= 0xffffffffffff0fffL
            mce |= bit(11)

        return mce

    def __prep_TLB(self, mce):
        # cleanup fields first
        mce &= 0xffffffffffe00010L

        # ErrorCodeExt[19:16] selects between TLB error types
        # BD introduces a locked TLB miss with EEC=0x2
        eec = randint(0,2)

        return mce | eec << 16

    def __prep_MEM(self, mce):
        # cleanup fields
        mce &= 0xffffffffffe00100L

        return mce

    def __prep_BUS(self, mce):
        # cleanup bytes first
        mce &= 0xffffffffffe00800L

        return mce


    def __gen_dc_mce(self, mce):
        """ Generate a DC MCE signature. Some of the fields are overlapping and
            not valid for all families but this is ok since we want to check the
            error path too when generating an invalid MCE or the MCi_STATUS
            somehow got corrupted
        """

        ec = mce & 0xffff

        # TLB
        if ec & bit(4):
            mce = self.__prep_TLB(mce)

            ll  = lls.index(choice(['L1' , 'L2']))

            mce |= 0x1 << 2 | ll  # TT=Data

        # MEM
        elif ec & bit(8):
            mce = self.__prep_MEM(mce)

            # BD introduces a bunch of EECs != 0
            eec = choice(range(0, 4) + range(16, 20))
            r4  = r4s.index(choice(['GEN', 'DRD', 'DWR', 'EV', 'SNP']))
            ll  = lls.index(choice(['LG', 'L1' , 'L2']))

            mce |= eec << 16 | r4 << 4 | 0x1 << 2 | ll  # TT=Data

        # BUS
        elif ec & bit(11):
            mce = self.__prep_BUS(mce)

            eec = randint(0, 2)
            pp  = pps.index(choice(['SRC', 'GEN']))
            r4  = r4s.index(choice(['GEN', 'RD', 'DRD', 'DWR']))
            ii  = iis.index(choice(['MEM', 'IO', 'GEN']))

            mce |= eec << 16 | pp << 9 | randint(0, 1) << 8 | r4 << 4 | ii << 2 | 0x3  # LL=LG

        return mce

    def __gen_ic_mce(self, mce):
        """ Generate an IC MCE signature.
        """

        ec = mce & 0xffff

        # TLB
        if ec & bit(4):
            mce = self.__prep_TLB(mce)
            mce |= lls.index(choice(['L1' , 'L2'])) # TT=Instr, already 0

        # MEM
        elif ec & bit(8):
            mce = self.__prep_MEM(mce)

            eec = choice(range(0, 11) + [13] + range(16, 21))
            r4  = r4s.index(choice(['IRD', 'SNP', 'EV']))
            ll  = lls.index(choice(['L1' , 'L2', 'LG']))

            mce |= eec << 16 | r4 << 4 | ll # TT=Instr

        # BUS
        elif ec & bit(11):
            mce = self.__prep_BUS(mce)

            # eec,pp,t,ii already 0
            # IRD, 5
            mce |= 5 << 4 | 3

        return mce


    def __gen_bu_mce(self, mce):
        """ Generate an BU MCE signature
            F12h has all three types based on ErrorCode: TLB, MEM and BUS

        """

        ec = mce & 0xffff
        # TLB
        if ec & bit(4):
            mce = self.__prep_TLB(mce)

            tt = tts.index(choice(['INSN', 'DATA']))

            mce |= tt << 2 | 0x1 # LL=L1

        # MEM
        elif ec & bit(8):
            mce = self.__prep_MEM(mce)

            eec = randint(0, 3)
            r4 = r4s.index(choice(['GEN', 'RD', 'WR', 'DRD', 'IRD', 'EV', 'SNP']))
            tt = tts.index(choice(['GEN', 'INSN', 'DATA']))
            ll = lls.index(choice(['LG' , 'L2']))

            mce |= eec << 16 | r4 << 4 | tt << 2 | ll

        # BUS
        elif ec & bit(11):
            mce = self.__prep_BUS(mce)

            r4 = r4s.index(choice(['RD', 'PRF']))
            ii = iis.index(choice(['MEM', 'IO']))

            mce |= r4 << 4 | ii << 2 | 0x3 # LL=LG


        return mce



    def __gen_cu_mce(self, mce):
        """ Generate an OR Combined Unit MCE
        """

        ec = mce & 0xffff

        # TLB
        if ec & bit(4):
            mce = self.__prep_TLB(mce)

            mce |= 0x2 << 2 | 0x2 # TT=GEN, LL=L2

        # MEM
        elif ec & bit(8):
            mce = self.__prep_MEM(mce)

            eec = choice(range(4, 13) + range(16, 21))
            r4  = r4s.index(choice(['DRD', 'IRD', 'PRF' 'DWR', 'SNP', 'EV', 'GEN']))
            tt  = tts.index(choice(['GEN', 'INSN', 'DATA']))
            ll  = lls.index(choice(['LG' , 'L1', 'L2']))

            mce |= eec << 16 | r4 << 4 | tt << 2 | ll

        # BUS
        elif ec & bit(11):
            mce = self.__prep_BUS(mce)

            eec = randint(0, 2)
            r4  = r4s.index(choice(['RD', 'DWR']))
            ii  = iis.index(choice(['MEM', 'IO']))
            ll  = lls.index(choice(['L1', 'L2']))

            mce |= eec << 16 | r4 << 4 | ii << 2 | ll # PP=SRC, T=0

        return mce


    def __gen_ls_mce(self, mce):
        """ Generate an LS MCE signature
        """

        # LS MCEs are only of type BUS so set bit 11
        mce |= bit(11)

        mce = self.__prep_BUS(mce)
        r4 = r4s.index(choice(['DRD', 'DWR']))
        ii = iis.index(choice(['MEM', 'IO']))

        mce |= r4 << 4 | ii << 2 | 0x3 # LL=LG

        return mce


    def __gen_nb_mce(self, mce):
        """ Generate an NB MCE signature
        """
        ec = mce & 0xffff

        # TLB
        if ec & bit(4):
            mce = self.__prep_TLB(mce)

            eec = choice([5, 15]) # GART Err, GART TLB Walk Data Err

            mce |= eec << 16 | 0x2 << 2 | 0x3 # GEN, LG

        # MEM
        elif ec & bit(8):
            mce = self.__prep_MEM(mce)

            eec = choice([25, 28, 29, 30, 31])
            r4  = r4s.index(choice(['GEN', 'RD', 'WR', 'EV', 'SNP']))
            tt  = tts.index(choice(['GEN', 'DATA']))

            mce |= eec << 16 | r4 << 4 | tt << 2 | 0x3 # LG

        # BUS
        elif ec & 0x0080:
            mce = self.__prep_BUS(mce)

            eec = choice(range(1, 5) + range(6, 16))
            pp  = pps.index(choice(pps))    # yes, all 4 are possible
            r4  = r4s.index(choice(['GEN', 'RD', 'WR', 'DWR']))
            ii  = iis.index(choice(['MEM', 'IO', 'GEN']))

            mce |= eec << 16 | pp << 9 | randint(0, 1) << 8 | r4 << 4 | ii << 2 | 0x3 # LL=LG

        return mce


    def __gen_fr_mce(self, mce):
        """ Generate a FR MCE signature
        """

        # FR/EX MCEs are only of type BUS so set bit 11
        mce |= bit(11)

        # BD-specific
        eec = randint(0, 12)

        mce = self.__prep_BUS(mce)
        mce |= eec << 16 | 0x3 << 9 | randint(0,1) << 8 | 0x3 << 2 | 0x3 # PP=GEN, R4=GEN, II=GEN, LL=LG

        return mce


    def gen_mce(self):
        mce     = getrandbits(64)

        # remove reserved stuff, along with clearing syndrome bits[54:47,31:24]
        mce &= 0xfe006100000fffff

        # Valid
        mce |= bit(63)

        # set CECC, UECC according to bit 61, UC: error couldn't be corrected by hw
        if mce & bit(61):
            mce &= ~bit(46)
            mce |= bit(45)
        else:
            mce |= bit(46)
            mce &= ~bit(45)

        # EN should be always set, otherwise moot
        mce |= bit(60)

        if self.err_type:
            # Clear error type bits so that later we don't get confused
            mce &= 0xfffffffffffff6ef

            if self.err_type == 'TLB':
                mce |= bit(4)
            elif self.err_type == 'MEM':
                mce |= bit(8)
            else:
                mce |= bit(11)

        if self.__is_ecc(mce):
            syndrome = getrandbits(16)
            mce |= ((syndrome & 0x0f) << 47)
            mce |= ((syndrome & 0xf0) << 20)
            self.syndrome = syndrome

        if self.fu == 'DC':
            mce = self._sanitize_error_type(mce)
            mce = self.__gen_dc_mce(mce)
        elif self.fu == 'IC':
            mce = self._sanitize_error_type(mce)
            mce = self.__gen_ic_mce(mce)
        elif self.fu == 'BU':
            mce = self._sanitize_error_type(mce)
            mce = self.__gen_bu_mce(mce)
        elif self.fu == 'CU':
            mce = self._sanitize_error_type(mce)
            mce = self.__gen_cu_mce(mce)
        elif self.fu == 'LS':
            mce = self.__gen_ls_mce(mce)
        elif self.fu == 'NB':
            mce = self._sanitize_error_type(mce)
            mce = self.__gen_nb_mce(mce)
        elif self.fu == 'FR' or self.fu == 'EX' or self.fu == 'FP':
            mce = self.__gen_fr_mce(mce)

        self.mci_status = mce

    def __is_bit_set(self, bit):
        if bit < 0 or bit > 63:
            return False
        if self.mci_status & (1 << bit):
            return True

        return False

    def valid(self):        return self.__is_bit_set(63)
    def overflow(self):     return self.__is_bit_set(62)
    def uncorrected(self):  return self.__is_bit_set(61)
    def err_enabled(self):  return self.__is_bit_set(60)
    def miscv(self):        return self.__is_bit_set(59)
    def addrv(self):        return self.__is_bit_set(58)
    def pcc(self):          return self.__is_bit_set(57)
    def cecc(self):         return self.__is_bit_set(46)
    def uecc(self):         return self.__is_bit_set(45)
    def scrub(self):        return self.__is_bit_set(40)

    def decode_eec(self):
        return eecs[self.eec()]

    def decode_tt(self):    return tts[(self.mci_status >> 2) & 0x3]
    def decode_ll(self):    return lls[self.mci_status & 0x3]
    def decode_pp(self):    return pps[(self.mci_status >> 9) & 0x3]
    def decode_ii(self):    return iis[(self.mci_status >> 2) & 0x3]

    def decode_r4(self):
        r4 = (self.mci_status >> 4) & 0xf

        if r4 > 8:
            return "-"

        return r4s[r4]

    def decode_t(self):
        t = (self.mci_status >> 8) & 0x1

        if t:
            return "TIMOUT"
        return "NOTIMOUT"

    def error_type(self):
        ec = self.mci_status & 0xffff

        if   (ec & 0xfff0) == bit(4):
            return "TLB(tt:" + self.decode_tt() + ";ll:" + self.decode_ll() + ")"
        elif (ec & 0xff00) == bit(8):
            return "MEM(r4:" + self.decode_r4() + ";tt:" + self.decode_tt() + \
                   ";ll:" + self.decode_ll() + ")"
        elif (ec & 0xF800) == bit(11):
            return "BUS(pp:" + self.decode_pp() + ";t:" + self.decode_t() + \
                   ";r4:"    + self.decode_r4() + ";ii:" + self.decode_ii() + \
                   ";ll:"    + self.decode_ll() + ")"
        else:
            return "WTF?!"

    def __repr__(self):
        ret = []

        if self.valid():        ret.append("Val")
        if self.overflow():     ret.append("Over")
        if self.uncorrected():  ret.append("UC")
        if self.err_enabled():  ret.append("EN")
        if self.miscv():        ret.append("MiscV")
        if self.addrv():        ret.append("AddrV")
        if self.pcc():          ret.append("PCC")
        if self.cecc():         ret.append("CECC")
        if self.uecc():         ret.append("UECC")
        if self.scrub():        ret.append("Scrub")

        dec_bits = '|'.join(ret)

        dec_bits += "|EEC: " + self.decode_eec() + (" (0x%02x)" % (self.eec()))

        if self.__is_ecc():
            dec_bits += (" (synd=0x%04x)" % (self.syndrome))

        dec_bits += "|ET: " + self.error_type()

        return ("MC%d_STATUS[%s]: 0x%016x" % (fus[self.fu], dec_bits, self.mci_status))



def _rw_file(fname, off, flags):
    """ Open and advance into @fname. Don't forget
        to close the fd which this function returns.
    """

    dbg("open %s" % fname)

    try:
        fd = open(fname, flags)
    except:
        err("opening %s" % (fname))
        return -1

    try:
        fd.seek(off, 0)
    except:
        err("skipping to offset %d" % (off))
        close(fd)
        return -1

    return fd

def read_file(fname, off, size):

    fd = _rw_file(fname, off, "rb")
    if fd < 0:
        return -1

    try:
        ret = fd.read(size)
    except:
        err("reading from %s" % fname)
        ret = -1

    fd.close()

    return ret

def write_file(fname, off, value):

    fd = _rw_file(fname, off, "wb")
    if fd < 0:
        return -1

    fd.write(value)
    fd.close()

    return 0

def rdmsr_on_cpu(cpu, msr):
    """ Use kernel /dev/cpu/*/msr interface to access an MSR
    """

    path = "/dev/cpu/%d/msr" % (cpu, )

    val = read_file(path, msr, 8)
    if not val or val < 0:
        err("Unable to read %s." % (path))
        return None

    if len(val) == 8:
        val = struct.unpack("Q", val)[0]
    else:
        err("MSR value truncated")
        return None

    return val

def wrmsr_on_cpu(cpu, msr, val):
    """ Use kernel /dev/cpu/%d/msr interface to write a MSR
    """

    path = "/dev/cpu/%d/msr" % (cpu, )

    packed_val = struct.pack('Q', val)

    if write_file(path, msr, packed_val):
        err("writing 0x%016x to MSR_0x%08x" % (val, msr))

def __toggle_raw_mce_inject(cpu, enable):

    val = rdmsr_on_cpu(cpu, MSR_K7_HWCR)
    if not val:
        return

    dbg("Pre:  0x%016x" % val)

    if enable:
        val |=  bit(18)
    else:
        val &= ~bit(18)

    dbg("Post: 0x%016x" % val)

    wrmsr_on_cpu(cpu, MSR_K7_HWCR, val)

def _inject_raw_mce(cpu, mce):
    """ Inject a raw MCE by writing the MCA registers directly
    """

    bank = fus[mce.fu]

    dbg("bank %d on cpu %d" % (bank, cpu))

    __toggle_raw_mce_inject(cpu, True)

    wrmsr_on_cpu(cpu, MSR_IA32_MCx_STATUS(bank), mce.mci_status)
    wrmsr_on_cpu(cpu, MSR_IA32_MCx_ADDR(bank), 0xbabedeaddeadbeef)
    wrmsr_on_cpu(cpu, MSR_IA32_MCx_MISC(bank), 0xdead57ac1ba0babe)

    if write_file("/sys/inject/cpu", 0, str(cpu)):
        err("injecting RAW MCE")

    __toggle_raw_mce_inject(cpu, False)


def _inject_ecc():
    """ DRAM ECC injection over PCI config space
    """
                 # ArraySelect=1000b | ArrayAddress[2:1]
    array_addr = bit(31) | randint(0, 4) << 1
                 # ErrInjEn[28:20] | EccWrReq | EccVector[15:0] - single-bit errors only for CECC
    array_data = bit(randint(20, 29)) | bit(17)  | bit(randint(0, 16))

    cmd_arr = ['setpci', '-s 18.3', ("0xb8.l=0x%08x" % array_addr)]
    dbg(cmd_arr)

    cmd_dat = ['setpci', '-s 18.3', ("0xbc.l=0x%08x" % array_data)]
    dbg(cmd_dat)

    try:
        subprocess.check_call(cmd_arr)
    except:
        sys.stderr.write("Error running %s\n" % (cmd_arr, ))
        return

    try:
        subprocess.check_call(cmd_dat)
    except:
        sys.stderr.write("Error running %s\n" % (cmd_dat, ));


def _inject_mce(cpu, mce, hw=False):
    """ Injects and MCE error over EDAC's /sysfs
    """

    sysfs_prefix = '/sys/devices/system/edac/mce'

    mce_hw_inject_file  = sysfs_prefix + '/hw_inject'
    mce_status_file     = sysfs_prefix + '/status'
    mce_bank_file       = sysfs_prefix + '/bank'

    if write_file(mce_status_file, 0, ("0x%016x" % (mce.mci_status))):
        print "Cannot open %s" % (mce_status_file)
        print "Have you forgotten modprobing mce_amd_inj.ko?"
        return

    if hw:
        if write_file(mce_hw_inject_file, 0, '1'):
            err("Cannot write to %s" % (mce_hw_inject_file))
            return

    if write_file(mce_bank_file, 0, ("%d" % (fus[mce.fu]))):
            err("Cannot write to %s" % (mce_bank_file))


def inject_mce(opts, mce):
    if opts.i == 'hw':
        _inject_mce(opts.cpu, mce, True)
    elif opts.i == 'ecc':
        _inject_ecc()
    elif opts.i == 'raw':
        _inject_raw_mce(opts.cpu, mce)
    elif opts.i == 'sw':
        _inject_mce(opts.cpu, mce)
    else:
        err("Unknown injection method: %s" % (opts.i, ))

def init_parser():
    """ Read cmdline options

        returns:
        options:dict -- config options
    """

    global opts

    parser = OptionParser()

    parser.add_option(
            "-c",
            "--cpu",
            type="int",
            dest="cpu",
            default=0,
            help="CPU to inject the MCE on",
    )

    parser.add_option(
            "-d",
            "--decode",
            type="string",
            action="store",
            dest="d",
            help="Decode 64-bit MCi_STATUS value representing an MCE"
    )

    parser.add_option(
            "",
            "--dbg",
            dest="dbg",
            action="store_true",
            default=False,
            help="Enable debugging",
    )

    def fam_callback(option, opt_str, value, parser):

        if value == 'R':
            parser.values.f = choice(families)
        elif value in families:
            parser.values.f = value
        else:
            # generate F10h MCEs per default
            parser.values.f = 'f10h'

    parser.add_option(
            "-f",
            "--family",
            dest="f",
            type="string",
            action="callback",
            callback=fam_callback,
            help=("Family to generate MCE for %s" % (families))
    )

    parser.add_option(
            "-i",
            "--inject",
            dest="i",
            type="string",
            help="Inject the error: 'hw' for hardware MCE injection\
                                    'sw' for software-only\
                                    'ecc' for DRAM ECC error\
                                    'raw' for raw MCE injection (needs kernel mod)"
    )

    def et_callback(option, opt_str, value, parser):

        value = value.upper()

        if value not in error_types:
            sys.stderr.write(("WARNING: wrong error type: %s\n" % (value)))

        parser.values.et = value

    parser.add_option(
            "-t",
            "--error-type",
            dest="et",
            type="string",
            action="callback",
            callback=et_callback,
            help=("Generate a specific error type: %s" % (error_types))
    )

    def fu_callback(option, opt_str, value, parser):

        # supplied string could be lowercase
        value = value.upper()

        # randomize FUs
        if value == 'R':
            # don't generate FP MCE yet
            k = fus.keys()
            k.remove('FP')
            parser.values.fu = choice(k)
        elif value in fus.keys():
            parser.values.fu = value

    parser.add_option(
            "-u",
            "--functional-unit",
            dest="fu",
            type="string",
            action="callback",
            callback=fu_callback,
            help=("Functional unit to generate MCE for %s" % (fus.keys())),
    )

    opts = parser.parse_args()[0]
    return opts

def main():

    opts = init_parser()

    if opts.d:
        if opts.fu:
            m = MCE(val=int(opts.d, 16), fu=opts.fu)
            print m
        else:
            err("You need to supply the functional unit this signature belongs to.\n")
            sys.exit(-1)
    else:
        if not opts.fu:
            opts.fu = choice(fus.keys())
            print "Selecting FU at random:", opts.fu

        m = MCE(fu=opts.fu, err_type=opts.et)
        sys.stderr.write(("Generating an %s MCE:\n%s\n" % (opts.fu, m)))

    if opts.i:
        inject_mce(opts, m)

if __name__ == "__main__":
    main()

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 01/18] perf: Start the restructuring
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 02/18] perf: Add persistent event facilities Borislav Petkov
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

mv kernel/perf_event.c -> kernel/events/core.c. From there, all further
sensible splitting can happen.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 kernel/Makefile                        |    5 +++--
 kernel/events/Makefile                 |    5 +++++
 kernel/{perf_event.c => events/core.c} |    0
 3 files changed, 8 insertions(+), 2 deletions(-)
 create mode 100644 kernel/events/Makefile
 rename kernel/{perf_event.c => events/core.c} (100%)

diff --git a/kernel/Makefile b/kernel/Makefile
index 85cbfb3..7981530 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -21,7 +21,6 @@ CFLAGS_REMOVE_mutex-debug.o = -pg
 CFLAGS_REMOVE_rtmutex-debug.o = -pg
 CFLAGS_REMOVE_cgroup-debug.o = -pg
 CFLAGS_REMOVE_sched_clock.o = -pg
-CFLAGS_REMOVE_perf_event.o = -pg
 CFLAGS_REMOVE_irq_work.o = -pg
 endif
 
@@ -103,7 +102,9 @@ obj-$(CONFIG_RING_BUFFER) += trace/
 obj-$(CONFIG_TRACEPOINTS) += trace/
 obj-$(CONFIG_SMP) += sched_cpupri.o
 obj-$(CONFIG_IRQ_WORK) += irq_work.o
-obj-$(CONFIG_PERF_EVENTS) += perf_event.o
+
+obj-$(CONFIG_PERF_EVENTS) += events/
+
 obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
 obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o
 obj-$(CONFIG_PADATA) += padata.o
diff --git a/kernel/events/Makefile b/kernel/events/Makefile
new file mode 100644
index 0000000..26c00e4
--- /dev/null
+++ b/kernel/events/Makefile
@@ -0,0 +1,5 @@
+ifdef CONFIG_FUNCTION_TRACER
+CFLAGS_REMOVE_core.o = -pg
+endif
+
+obj-y += core.o
diff --git a/kernel/perf_event.c b/kernel/events/core.c
similarity index 100%
rename from kernel/perf_event.c
rename to kernel/events/core.c
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 02/18] perf: Add persistent event facilities
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
  2011-04-23 16:28 ` [PATCH 01/18] perf: Start the restructuring Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-26 10:57   ` Peter Zijlstra
  2011-04-23 16:28 ` [PATCH 03/18] x86, mce: Add persistent MCE event Borislav Petkov
                   ` (16 subsequent siblings)
  18 siblings, 1 reply; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Add a barebones implementation for registering persistent events with
perf. For that, we don't destroy the buffers when they're unmapped and
we map them read-only so that multiple agents can access them.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 include/linux/perf_event.h |   22 ++++++++++++++++-
 kernel/events/Makefile     |    2 +-
 kernel/events/core.c       |   30 ++++++++++++++++++----
 kernel/events/persistent.c |   56 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 102 insertions(+), 8 deletions(-)
 create mode 100644 kernel/events/persistent.c

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index ee9f1e7..37bfae1 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -216,8 +216,9 @@ struct perf_event_attr {
 				precise_ip     :  2, /* skid constraint       */
 				mmap_data      :  1, /* non-exec mmap data    */
 				sample_id_all  :  1, /* sample_type all events */
+				persistent     :  1, /* event always on */
 
-				__reserved_1   : 45;
+				__reserved_1   : 44;
 
 	union {
 		__u32		wakeup_events;	  /* wakeup every n events */
@@ -1159,6 +1160,15 @@ extern void perf_swevent_put_recursion_context(int rctx);
 extern void perf_event_enable(struct perf_event *event);
 extern void perf_event_disable(struct perf_event *event);
 extern void perf_event_task_tick(void);
+extern struct perf_buffer *
+perf_buffer_alloc(int nr_pages, long watermark, int cpu, int flags);
+extern void perf_buffer_put(struct perf_buffer *buffer);
+extern struct perf_event *
+perf_enable_persistent_event(struct perf_event_attr *attr,
+			     int cpu, unsigned bufsz);
+extern void perf_disable_persistent_event(struct perf_event *event, int cpu);
+extern int perf_persistent_open(struct inode *inode, struct file *file);
+extern const struct file_operations perf_pers_fops;
 #else
 static inline void
 perf_event_task_sched_in(struct task_struct *task)			{ }
@@ -1193,6 +1203,16 @@ static inline void perf_swevent_put_recursion_context(int rctx)		{ }
 static inline void perf_event_enable(struct perf_event *event)		{ }
 static inline void perf_event_disable(struct perf_event *event)		{ }
 static inline void perf_event_task_tick(void)				{ }
+static inline struct perf_buffer *
+perf_buffer_alloc(int nr_pages, long watermark, int cpu, int flags)	{ return NULL; }
+static inline void perf_buffer_put(struct perf_buffer *buffer)		{}
+static inline struct perf_event *
+perf_enable_persistent_event(struct perf_event_attr *attr, int cpu,
+			     unsigned bufsz)				{ return -EINVAL; }
+static inline void
+perf_disable_persistent_event(struct perf_event *event, int cpu)	{}
+static inline int
+perf_persistent_open(struct inode *inode, struct file *file)		{ return -1; }
 #endif
 
 #define perf_output_put(handle, x) \
diff --git a/kernel/events/Makefile b/kernel/events/Makefile
index 26c00e4..e2d4d8e 100644
--- a/kernel/events/Makefile
+++ b/kernel/events/Makefile
@@ -2,4 +2,4 @@ ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_core.o = -pg
 endif
 
-obj-y += core.o
+obj-y += core.o persistent.o
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 8e81a98..4a0c398 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2898,7 +2898,7 @@ static void free_event_rcu(struct rcu_head *head)
 	kfree(event);
 }
 
-static void perf_buffer_put(struct perf_buffer *buffer);
+void perf_buffer_put(struct perf_buffer *buffer);
 
 static void free_event(struct perf_event *event)
 {
@@ -3458,7 +3458,7 @@ static void *perf_mmap_alloc_page(int cpu)
 	return page_address(page);
 }
 
-static struct perf_buffer *
+struct perf_buffer *
 perf_buffer_alloc(int nr_pages, long watermark, int cpu, int flags)
 {
 	struct perf_buffer *buffer;
@@ -3575,7 +3575,7 @@ static void perf_buffer_free(struct perf_buffer *buffer)
 	schedule_work(&buffer->work);
 }
 
-static struct perf_buffer *
+struct perf_buffer *
 perf_buffer_alloc(int nr_pages, long watermark, int cpu, int flags)
 {
 	struct perf_buffer *buffer;
@@ -3676,7 +3676,7 @@ static struct perf_buffer *perf_buffer_get(struct perf_event *event)
 	return buffer;
 }
 
-static void perf_buffer_put(struct perf_buffer *buffer)
+void perf_buffer_put(struct perf_buffer *buffer)
 {
 	if (!atomic_dec_and_test(&buffer->refcount))
 		return;
@@ -3695,6 +3695,11 @@ static void perf_mmap_close(struct vm_area_struct *vma)
 {
 	struct perf_event *event = vma->vm_file->private_data;
 
+	if (event->attr.persistent) {
+		atomic_dec(&event->mmap_count);
+		return;
+	}
+
 	if (atomic_dec_and_mutex_lock(&event->mmap_count, &event->mmap_mutex)) {
 		unsigned long size = perf_data_size(event->buffer);
 		struct user_struct *user = event->mmap_user;
@@ -3737,7 +3742,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
 	if (event->cpu == -1 && event->attr.inherit)
 		return -EINVAL;
 
-	if (!(vma->vm_flags & VM_SHARED))
+	if (!(vma->vm_flags & VM_SHARED) && !event->attr.persistent)
 		return -EINVAL;
 
 	vma_size = vma->vm_end - vma->vm_start;
@@ -3846,6 +3851,16 @@ static const struct file_operations perf_fops = {
 	.fasync			= perf_fasync,
 };
 
+const struct file_operations perf_pers_fops = {
+	.llseek		= no_llseek,
+	.open		= perf_persistent_open,
+	.poll		= perf_poll,
+	.unlocked_ioctl	= perf_ioctl,
+	.compat_ioctl	= perf_ioctl,
+	.mmap		= perf_mmap,
+	.fasync		= perf_fasync,
+};
+
 /*
  * Perf event wakeup
  *
@@ -6702,7 +6717,6 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
 	mutex_unlock(&ctx->mutex);
 
 	return event;
-
 err_free:
 	free_event(event);
 err:
@@ -6756,6 +6770,10 @@ __perf_event_exit_task(struct perf_event *child_event,
 		raw_spin_unlock_irq(&child_ctx->lock);
 	}
 
+	/* do not remove persistent events on task exit */
+	if (child_event->attr.persistent)
+		return;
+
 	perf_remove_from_context(child_event);
 
 	/*
diff --git a/kernel/events/persistent.c b/kernel/events/persistent.c
new file mode 100644
index 0000000..495ff87
--- /dev/null
+++ b/kernel/events/persistent.c
@@ -0,0 +1,56 @@
+#include <linux/perf_event.h>
+
+/*
+ * Pass in the @event pointer which receives the allocated event from
+ * perf on success. Check return code before touching @event further.
+ *
+ * @attr: perf attr template
+ * @cpu: on which cpu
+ * @nr_pages: perf buffer size in pages
+ *
+ */
+struct perf_event *perf_enable_persistent_event(struct perf_event_attr *attr,
+						int cpu, unsigned nr_pages)
+{
+	struct perf_buffer *buffer;
+	struct perf_event *ev;
+
+	ev = perf_event_create_kernel_counter(attr, cpu, NULL, NULL);
+	if (IS_ERR(ev))
+		return ev;
+
+	buffer = perf_buffer_alloc(nr_pages, 0, cpu, PERF_BUFFER_WRITABLE);
+	if (IS_ERR(buffer))
+		goto err;
+
+	rcu_assign_pointer(ev->buffer, buffer);
+	perf_event_enable(ev);
+
+	return ev;
+
+err:
+	perf_event_release_kernel(ev);
+	return ERR_PTR(-EINVAL);
+}
+
+void perf_disable_persistent_event(struct perf_event *event, int cpu)
+{
+	if (!event)
+		return;
+
+	perf_event_disable(event);
+
+	if (event->buffer) {
+		perf_buffer_put(event->buffer);
+		rcu_assign_pointer(event->buffer, NULL);
+	}
+
+	perf_event_release_kernel(event);
+}
+
+int perf_persistent_open(struct inode *inode, struct file *file)
+{
+	file->private_data = inode->i_private;
+
+	return 0;
+}
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 03/18] x86, mce: Add persistent MCE event
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
  2011-04-23 16:28 ` [PATCH 01/18] perf: Start the restructuring Borislav Petkov
  2011-04-23 16:28 ` [PATCH 02/18] perf: Add persistent event facilities Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 04/18] x86, mce: Have MCE persistent event off by default for now Borislav Petkov
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Add the necessary glue to enable the mce_record tracepoint on boot,
turning it into a persistent event. This exports the MCE buffer through
a debugfs per-CPU file which a userspace daemon can read and process the
error data further.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 arch/x86/include/asm/mce.h       |    8 +++
 arch/x86/kernel/cpu/mcheck/mce.c |   89 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h
index eb16e94..81f5545 100644
--- a/arch/x86/include/asm/mce.h
+++ b/arch/x86/include/asm/mce.h
@@ -115,6 +115,14 @@ struct mce_log {
 
 #ifdef __KERNEL__
 
+/*
+ * a per-cpu descriptor of the persistent MCE tracepoint
+ */
+struct mce_tp_desc {
+	struct perf_event *event;
+	struct dentry *debugfs_entry;
+};
+
 extern struct atomic_notifier_head x86_mce_decoder_chain;
 
 #include <linux/percpu.h>
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 3385ea2..9589ebf 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -96,6 +96,7 @@ static char			*mce_helper_argv[2] = { mce_helper, NULL };
 
 static DECLARE_WAIT_QUEUE_HEAD(mce_wait);
 static DEFINE_PER_CPU(struct mce, mces_seen);
+static DEFINE_PER_CPU(struct mce_tp_desc, mce_event);
 static int			cpu_missing;
 
 /*
@@ -2055,6 +2056,91 @@ static void __cpuinit mce_reenable_cpu(void *h)
 	}
 }
 
+static struct perf_event_attr pattr = {
+	.type		= PERF_TYPE_TRACEPOINT,
+	.size		= sizeof(pattr),
+	.sample_type	= PERF_SAMPLE_RAW,
+	.persistent	= 1,
+};
+
+static struct dentry *mce_add_event_debugfs(struct perf_event *event, int cpu)
+{
+	char buf[14];
+
+	sprintf(buf, "mce_record%d", cpu);
+
+	return debugfs_create_file(buf, S_IRUGO | S_IWUSR,
+				   mce_get_debugfs_dir(),
+				   event, &perf_pers_fops);
+}
+
+#define MCE_BUF_PAGES	4
+
+static int mce_enable_perf_event_on_cpu(int cpu)
+{
+	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
+	int err = -EINVAL;
+
+	d->event = perf_enable_persistent_event(&pattr, cpu, MCE_BUF_PAGES);
+	if (IS_ERR(d->event)) {
+		printk(KERN_ERR "MCE: Error enabling event on cpu %d\n", cpu);
+		goto ret;
+	}
+
+	d->debugfs_entry = mce_add_event_debugfs(d->event, cpu);
+	if (!d->debugfs_entry) {
+		printk(KERN_ERR "MCE: Error adding event debugfs entry on cpu %d\n", cpu);
+		goto disable;
+	}
+
+	return 0;
+
+disable:
+	perf_disable_persistent_event(d->event, cpu);
+
+ret:
+	return err;
+}
+
+static void mce_disable_perf_event_on_cpu(int cpu)
+{
+	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
+	debugfs_remove(d->debugfs_entry);
+	perf_disable_persistent_event(d->event, cpu);
+}
+
+static __init int mcheck_init_persistent_event(void)
+{
+	int cpu, err = 0;
+
+	get_online_cpus();
+
+	pattr.config = event_mce_record.event.type;
+	pattr.sample_period = 1;
+	pattr.wakeup_events = 1;
+
+	for_each_online_cpu(cpu)
+		if (mce_enable_perf_event_on_cpu(cpu))
+			goto err_unwind;
+
+	goto unlock;
+
+err_unwind:
+	err = -EINVAL;
+	for (--cpu; cpu >= 0; cpu--)
+		mce_disable_perf_event_on_cpu(cpu);
+
+unlock:
+	put_online_cpus();
+
+	return err;
+}
+
+/*
+ * This has to run after event_trace_init()
+ */
+device_initcall(mcheck_init_persistent_event);
+
 /* Get notified when a cpu comes on/off. Be hotplug friendly. */
 static int __cpuinit
 mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
@@ -2068,6 +2154,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 		mce_create_device(cpu);
 		if (threshold_cpu_callback)
 			threshold_cpu_callback(action, cpu);
+		mce_enable_perf_event_on_cpu(cpu);
 		break;
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN:
@@ -2077,6 +2164,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 		break;
 	case CPU_DOWN_PREPARE:
 	case CPU_DOWN_PREPARE_FROZEN:
+		mce_disable_perf_event_on_cpu(cpu);
 		del_timer_sync(t);
 		smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
 		break;
@@ -2088,6 +2176,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 			add_timer_on(t, cpu);
 		}
 		smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
+		mce_enable_perf_event_on_cpu(cpu);
 		break;
 	case CPU_POST_DEAD:
 		/* intentionally ignoring frozen here */
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 04/18] x86, mce: Have MCE persistent event off by default for now
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (2 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 03/18] x86, mce: Add persistent MCE event Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 05/18] perf: Add Makefile.lib Borislav Petkov
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Since this is a pretty new functionality and since it affects all x86,
we want to have it off by default for now, in case something goes awry.
You can always enable it by supplying "ras" on your kernel command line.

Also, depending on whether it is enabled or not, we emit the tracepoint
from a different place in the code to pick up any decoded info.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 Documentation/kernel-parameters.txt |    2 ++
 arch/x86/include/asm/mce.h          |    1 +
 arch/x86/kernel/cpu/mcheck/mce.c    |   32 ++++++++++++++++++++++++++++++--
 drivers/edac/mce_amd.c              |    5 +++++
 4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index cc85a92..f09438a 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -2165,6 +2165,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 	ramdisk_size=	[RAM] Sizes of RAM disks in kilobytes
 			See Documentation/blockdev/ramdisk.txt.
 
+	ras		[X86] Enable RAS daemon supporting functionality.
+
 	rcupdate.blimit=	[KNL,BOOT]
 			Set maximum number of finished RCU callbacks to process
 			in one batch.
diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h
index 81f5545..8872af9 100644
--- a/arch/x86/include/asm/mce.h
+++ b/arch/x86/include/asm/mce.h
@@ -131,6 +131,7 @@ extern struct atomic_notifier_head x86_mce_decoder_chain;
 
 extern int mce_disabled;
 extern int mce_p5_enabled;
+extern int ras;
 
 #ifdef CONFIG_X86_MCE
 int mcheck_init(void);
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 9589ebf..54b411f 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -59,6 +59,8 @@ static DEFINE_MUTEX(mce_read_mutex);
 #define CREATE_TRACE_POINTS
 #include <trace/events/mce.h>
 
+EXPORT_TRACEPOINT_SYMBOL_GPL(mce_record);
+
 int mce_disabled __read_mostly;
 
 #define MISC_MCELOG_MINOR	227
@@ -86,6 +88,7 @@ static int			mce_dont_log_ce		__read_mostly;
 int				mce_cmci_disabled	__read_mostly;
 int				mce_ignore_ce		__read_mostly;
 int				mce_ser			__read_mostly;
+int				ras			__read_mostly;
 
 struct mce_bank                *mce_banks		__read_mostly;
 
@@ -105,6 +108,7 @@ static int			cpu_missing;
  */
 ATOMIC_NOTIFIER_HEAD(x86_mce_decoder_chain);
 EXPORT_SYMBOL_GPL(x86_mce_decoder_chain);
+EXPORT_SYMBOL_GPL(ras);
 
 static int default_decode_mce(struct notifier_block *nb, unsigned long val,
 			       void *data)
@@ -163,8 +167,9 @@ void mce_log(struct mce *mce)
 {
 	unsigned next, entry;
 
-	/* Emit the trace record: */
-	trace_mce_record(mce);
+	if (!ras)
+		/* Emit the trace record: */
+		trace_mce_record(mce);
 
 	mce->finished = 0;
 	wmb();
@@ -1721,6 +1726,19 @@ static int __init mcheck_enable(char *str)
 }
 __setup("mce", mcheck_enable);
 
+static int __init ras_enable(char *str)
+{
+	/*
+	 * We enable the persistent event only if "ras" is supplied on the
+	 * command line. We still can add further options to parameter later.
+	 */
+	ras = 1;
+
+	return 0;
+}
+
+__setup("ras", ras_enable);
+
 int __init mcheck_init(void)
 {
 	atomic_notifier_chain_register(&x86_mce_decoder_chain, &mce_dec_nb);
@@ -2081,6 +2099,9 @@ static int mce_enable_perf_event_on_cpu(int cpu)
 	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
 	int err = -EINVAL;
 
+	if (!ras)
+		return 0;
+
 	d->event = perf_enable_persistent_event(&pattr, cpu, MCE_BUF_PAGES);
 	if (IS_ERR(d->event)) {
 		printk(KERN_ERR "MCE: Error enabling event on cpu %d\n", cpu);
@@ -2105,6 +2126,10 @@ ret:
 static void mce_disable_perf_event_on_cpu(int cpu)
 {
 	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
+
+	if (!ras)
+		return;
+
 	debugfs_remove(d->debugfs_entry);
 	perf_disable_persistent_event(d->event, cpu);
 }
@@ -2113,6 +2138,9 @@ static __init int mcheck_init_persistent_event(void)
 {
 	int cpu, err = 0;
 
+	if (!ras)
+		return -EBUSY;
+
 	get_online_cpus();
 
 	pattr.config = event_mce_record.event.type;
diff --git a/drivers/edac/mce_amd.c b/drivers/edac/mce_amd.c
index 795cfbc..e329335 100644
--- a/drivers/edac/mce_amd.c
+++ b/drivers/edac/mce_amd.c
@@ -1,5 +1,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <asm/mce.h>
+#include <trace/events/mce.h>
 
 #include "mce_amd.h"
 
@@ -829,6 +831,9 @@ int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 
 	amd_decode_err_code(m->status & 0xffff);
 
+	if (ras)
+		trace_mce_record(m);
+
 	return NOTIFY_STOP;
 }
 EXPORT_SYMBOL_GPL(amd_decode_mce);
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 05/18] perf: Add Makefile.lib
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (3 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 04/18] x86, mce: Have MCE persistent event off by default for now Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 06/18] tools: Add a toplevel Makefile Borislav Petkov
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Put build settings which will be reused by other tools into a common
.lib file.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/perf/Makefile        |   45 +------------------------------------------
 tools/scripts/Makefile.lib |   46 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 44 deletions(-)
 create mode 100644 tools/scripts/Makefile.lib

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 91ad5cc..ab9f667 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -1,18 +1,10 @@
-ifeq ("$(origin O)", "command line")
-	OUTPUT := $(O)/
-endif
+include ../scripts/Makefile.lib
 
 # The default target of this Makefile is...
 all:
 
 include config/utilities.mak
 
-ifneq ($(OUTPUT),)
-# check that the output directory actually exists
-OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
-$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
-endif
-
 # Define V to have a more verbose compile.
 #
 # Define PYTHON to point to the python binary if the default
@@ -54,31 +46,6 @@ ifeq ($(ARCH),x86_64)
 	ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S
 endif
 
-#
-# Include saner warnings here, which can catch bugs:
-#
-
-EXTRA_WARNINGS := -Wformat
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-security
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-y2k
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wshadow
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Winit-self
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wpacked
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wredundant-decls
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-aliasing=3
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-default
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-enum
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wno-system-headers
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wundef
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wwrite-strings
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wbad-function-cast
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-declarations
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-prototypes
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wnested-externs
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes
-EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement
-
 ifeq ("$(origin DEBUG)", "command line")
   PERF_DEBUG = $(DEBUG)
 endif
@@ -597,16 +564,6 @@ else
 	endif
 endif
 
-ifneq ($(findstring $(MAKEFLAGS),s),s)
-ifndef V
-	QUIET_CC       = @echo '   ' CC $@;
-	QUIET_AR       = @echo '   ' AR $@;
-	QUIET_LINK     = @echo '   ' LINK $@;
-	QUIET_MKDIR    = @echo '   ' MKDIR $@;
-	QUIET_GEN      = @echo '   ' GEN $@;
-endif
-endif
-
 ifdef ASCIIDOC8
 	export ASCIIDOC8
 endif
diff --git a/tools/scripts/Makefile.lib b/tools/scripts/Makefile.lib
new file mode 100644
index 0000000..854fefb
--- /dev/null
+++ b/tools/scripts/Makefile.lib
@@ -0,0 +1,46 @@
+ifeq ("$(origin O)", "command line")
+	OUTPUT := $(O)/
+endif
+
+ifneq ($(OUTPUT),)
+# check that the output directory actually exists
+OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
+$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
+endif
+
+#
+# Include saner warnings here, which can catch bugs:
+#
+
+EXTRA_WARNINGS := -Wformat
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-security
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-y2k
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wshadow
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Winit-self
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wpacked
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wredundant-decls
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-aliasing=3
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-default
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-enum
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wno-system-headers
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wundef
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wwrite-strings
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wbad-function-cast
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-declarations
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-prototypes
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wnested-externs
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement
+
+ifneq ($(findstring $(MAKEFLAGS),s),s)
+ifndef V
+	QUIET_CC       = @echo '   ' CC $@;
+	QUIET_AR       = @echo '   ' AR $@;
+	QUIET_LINK     = @echo '   ' LINK $@;
+	QUIET_MKDIR    = @echo '   ' MKDIR $@;
+	QUIET_GEN      = @echo '   ' GEN $@;
+endif
+endif
+
+
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 06/18] tools: Add a toplevel Makefile
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (4 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 05/18] perf: Add Makefile.lib Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 07/18] perf: Export trace-event utils Borislav Petkov
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Add a Makefile with all the targets under tools/. Make perf the default
one and add a minimalistic Makefile to slub/ for completeness.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/Makefile             |   42 ++++++++++++++++++++++++++++++++++++++++++
 tools/scripts/Makefile.lib |   14 ++++++++++++--
 tools/slub/Makefile        |    4 ++++
 3 files changed, 58 insertions(+), 2 deletions(-)
 create mode 100644 tools/Makefile
 create mode 100644 tools/slub/Makefile

diff --git a/tools/Makefile b/tools/Makefile
new file mode 100644
index 0000000..74b20a9
--- /dev/null
+++ b/tools/Makefile
@@ -0,0 +1,42 @@
+include scripts/Makefile.lib
+
+PERF_TOP_DIR := $(CURDIR)
+export PERF_TOP_DIR
+
+BASIC_CFLAGS = -I$(CURDIR)/lib
+
+# temporary for lib/trace/
+BASIC_CFLAGS += -I$(CURDIR)/perf/util/include
+export BASIC_CFLAGS
+
+perf: .FORCE
+	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1)
+
+firewire: .FORCE
+	$(QUIET_SUBDIR0)firewire/ $(QUIET_SUBDIR1)
+
+slabinfo: .FORCE
+	$(QUIET_SUBDIR0)slub/ $(QUIET_SUBDIR1)
+
+turbostat: .FORCE
+	$(QUIET_SUBDIR0)power/x86/turbostat/ $(QUIET_SUBDIR1)
+
+usb: .FORCE
+	$(QUIET_SUBDIR0)usb/ $(QUIET_SUBDIR1)
+
+virtio: .FORCE
+	$(QUIET_SUBDIR0)virtio/ $(QUIET_SUBDIR1)
+
+x86_energy: .FORCE
+	$(QUIET_SUBDIR0)power/x86/x86_energy_perf_policy/ $(QUIET_SUBDIR1)
+
+clean:
+	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)firewire/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)slub/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)power/x86/turbostat/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)usb/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)virtio/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)power/x86/x86_energy_perf_policy/ $(QUIET_SUBDIR1) clean
+
+.PHONY: clean .FORCE
diff --git a/tools/scripts/Makefile.lib b/tools/scripts/Makefile.lib
index 854fefb..9dfa0f9 100644
--- a/tools/scripts/Makefile.lib
+++ b/tools/scripts/Makefile.lib
@@ -33,6 +33,15 @@ EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition
 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes
 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement
 
+QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
+QUIET_SUBDIR1  =
+
+ifneq ($(findstring $(MAKEFLAGS),w),w)
+PRINT_DIR = --no-print-directory
+else # "make -w"
+NO_SUBDIR = :
+endif
+
 ifneq ($(findstring $(MAKEFLAGS),s),s)
 ifndef V
 	QUIET_CC       = @echo '   ' CC $@;
@@ -40,7 +49,8 @@ ifndef V
 	QUIET_LINK     = @echo '   ' LINK $@;
 	QUIET_MKDIR    = @echo '   ' MKDIR $@;
 	QUIET_GEN      = @echo '   ' GEN $@;
+	QUIET_SUBDIR0  = +@subdir=
+	QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
+			$(MAKE) $(PRINT_DIR) -C $$subdir
 endif
 endif
-
-
diff --git a/tools/slub/Makefile b/tools/slub/Makefile
new file mode 100644
index 0000000..b2cf6b4
--- /dev/null
+++ b/tools/slub/Makefile
@@ -0,0 +1,4 @@
+slabinfo: slabinfo.c
+
+clean:
+	rm -rf slabinfo
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 07/18] perf: Export trace-event utils
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (5 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 06/18] tools: Add a toplevel Makefile Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 08/18] perf: Remove duplicate enum trace_flag_type Borislav Petkov
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Export trace-event* utils into a sub-lib for wider use. While at it,
export functions for use by other entities later.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/Makefile                                     |    6 ++-
 tools/lib/trace/Makefile                           |   59 ++++++++++++++++++++
 .../trace-event-info.c => lib/trace/event-info.c}  |   20 +++----
 .../trace/event-parse.c}                           |   16 +++---
 .../trace-event-read.c => lib/trace/event-read.c}  |    4 +-
 tools/{perf/util => lib/trace}/trace-event.h       |   22 +++++--
 tools/perf/Makefile                                |   11 ++--
 tools/perf/bench/bench.h                           |    2 +
 tools/perf/builtin-kmem.c                          |    2 +-
 tools/perf/builtin-kvm.c                           |    2 +-
 tools/perf/builtin-lock.c                          |    2 +-
 tools/perf/builtin-sched.c                         |    2 +-
 tools/perf/builtin-script.c                        |    2 +-
 tools/perf/scripts/perl/Perf-Trace-Util/Context.c  |    2 +-
 .../perf/scripts/python/Perf-Trace-Util/Context.c  |    2 +-
 tools/perf/util/cache.h                            |    1 +
 tools/perf/util/header.c                           |    2 +-
 tools/perf/util/probe-event.c                      |    2 +-
 .../perf/util/scripting-engines/trace-event-perl.c |    2 +-
 .../util/scripting-engines/trace-event-python.c    |    2 +-
 tools/perf/util/trace-event-scripting.c            |    2 +-
 tools/scripts/Makefile.lib                         |    4 +
 22 files changed, 123 insertions(+), 46 deletions(-)
 create mode 100644 tools/lib/trace/Makefile
 rename tools/{perf/util/trace-event-info.c => lib/trace/event-info.c} (97%)
 rename tools/{perf/util/trace-event-parse.c => lib/trace/event-parse.c} (99%)
 rename tools/{perf/util/trace-event-read.c => lib/trace/event-read.c} (99%)
 rename tools/{perf/util => lib/trace}/trace-event.h (91%)

diff --git a/tools/Makefile b/tools/Makefile
index 74b20a9..48f0720 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -9,12 +9,15 @@ BASIC_CFLAGS = -I$(CURDIR)/lib
 BASIC_CFLAGS += -I$(CURDIR)/perf/util/include
 export BASIC_CFLAGS
 
-perf: .FORCE
+perf: libtrace .FORCE
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1)
 
 firewire: .FORCE
 	$(QUIET_SUBDIR0)firewire/ $(QUIET_SUBDIR1)
 
+libtrace: .FORCE
+	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1)
+
 slabinfo: .FORCE
 	$(QUIET_SUBDIR0)slub/ $(QUIET_SUBDIR1)
 
@@ -33,6 +36,7 @@ x86_energy: .FORCE
 clean:
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)firewire/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)slub/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)power/x86/turbostat/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)usb/ $(QUIET_SUBDIR1) clean
diff --git a/tools/lib/trace/Makefile b/tools/lib/trace/Makefile
new file mode 100644
index 0000000..dddc228
--- /dev/null
+++ b/tools/lib/trace/Makefile
@@ -0,0 +1,59 @@
+include ../../scripts/Makefile.lib
+
+CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
+
+# Make the path relative to DESTDIR, not to prefix
+ifndef DESTDIR
+prefix = $(HOME)
+endif
+bindir_relative = bin
+bindir = $(prefix)/$(bindir_relative)
+mandir = share/man
+infodir = share/info
+sharedir = $(prefix)/share
+ifeq ($(prefix),/usr)
+sysconfdir = /etc
+else
+sysconfdir = $(prefix)/etc
+endif
+
+export prefix bindir sharedir sysconfdir
+
+CC = $(CROSS_COMPILE)gcc
+AR = $(CROSS_COMPILE)ar
+RM = rm -f
+TAR = tar
+FIND = find
+INSTALL = install
+RPMBUILD = rpmbuild
+PTHREAD_LIBS = -lpthread
+
+ifeq ("$(origin V)", "command line")
+  VERBOSE = $(V)
+endif
+ifndef VERBOSE
+  VERBOSE = 0
+endif
+
+TRACE_LIB = $(LIB_OUTPUT)libtrace.a
+
+all: $(TRACE_LIB)
+
+TRACE_LIB_H += trace-event.h
+
+TRACE_LIB_OBJS += event-parse.o
+TRACE_LIB_OBJS += event-read.o
+TRACE_LIB_OBJS += event-info.o
+
+ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+
+$(OUTPUT)%.o: %.c
+	$(QUIET_CC)$(CC) -g -o $@ -c $(ALL_CFLAGS) $<
+
+$(TRACE_LIB): $(TRACE_LIB_OBJS) $(TRACE_LIB_H)
+	$(RM) $@;  $(AR) rcs $@ $(TRACE_LIB_OBJS)
+
+clean:
+	$(RM) *.a *.o *~ *.so $(TRACE_LIB)
+
+.PHONY: clean
diff --git a/tools/perf/util/trace-event-info.c b/tools/lib/trace/event-info.c
similarity index 97%
rename from tools/perf/util/trace-event-info.c
rename to tools/lib/trace/event-info.c
index 35729f4..5270a64 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/lib/trace/event-info.c
@@ -37,10 +37,10 @@
 #include <linux/list.h>
 #include <linux/kernel.h>
 
-#include "../perf.h"
+#include "../../perf/perf.h"
 #include "trace-event.h"
-#include "debugfs.h"
-#include "evsel.h"
+#include "../perf/util/debugfs.h"
+#include "../perf/util/evsel.h"
 
 #define VERSION "0.5"
 
@@ -72,8 +72,6 @@ struct events {
 	char *name;
 };
 
-
-
 static void die(const char *fmt, ...)
 {
 	va_list ap;
@@ -136,7 +134,7 @@ static const char *find_tracing_dir(void)
 	return tracing;
 }
 
-static char *get_tracing_file(const char *name)
+char *get_tracing_file(const char *name)
 {
 	const char *tracing;
 	char *file;
@@ -151,7 +149,7 @@ static char *get_tracing_file(const char *name)
 	return file;
 }
 
-static void put_tracing_file(char *file)
+void put_tracing_file(char *file)
 {
 	free(file);
 }
@@ -231,7 +229,7 @@ static unsigned long get_size_fd(int fd)
 	return size;
 }
 
-static unsigned long get_size(const char *file)
+unsigned long get_filesize(const char *file)
 {
 	unsigned long long size = 0;
 	int fd;
@@ -340,7 +338,7 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps)
 
 		if (ret >= 0) {
 			/* unfortunately, you can not stat debugfs files for size */
-			size = get_size(format);
+			size = get_filesize(format);
 			write_or_die(&size, 8);
 			check_size = copy_file(format);
 			if (size != check_size)
@@ -438,7 +436,7 @@ static void read_proc_kallsyms(void)
 		write_or_die(&size, 4);
 		return;
 	}
-	size = get_size(path);
+	size = get_filesize(path);
 	write_or_die(&size, 4);
 	check_size = copy_file(path);
 	if (size != check_size)
@@ -461,7 +459,7 @@ static void read_ftrace_printk(void)
 		write_or_die(&size, 4);
 		goto out;
 	}
-	size = get_size(path);
+	size = get_filesize(path);
 	write_or_die(&size, 4);
 	check_size = copy_file(path);
 	if (size != check_size)
diff --git a/tools/perf/util/trace-event-parse.c b/tools/lib/trace/event-parse.c
similarity index 99%
rename from tools/perf/util/trace-event-parse.c
rename to tools/lib/trace/event-parse.c
index 0a7ed5b..4a52cb8 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/lib/trace/event-parse.c
@@ -29,8 +29,8 @@
 #include <errno.h>
 
 #undef _GNU_SOURCE
-#include "../perf.h"
-#include "util.h"
+#include "../../perf/perf.h"
+#include "../../perf/util/util.h"
 #include "trace-event.h"
 
 int header_page_ts_offset;
@@ -44,7 +44,7 @@ int header_page_data_size;
 
 bool latency_format;
 
-static char *input_buf;
+static const char *input_buf;
 static unsigned long long input_buf_ptr;
 static unsigned long long input_buf_siz;
 
@@ -56,7 +56,7 @@ static int is_symbolic_field;
 static struct format_field *
 find_any_field(struct event *event, const char *name);
 
-static void init_input_buf(char *buf, unsigned long long size)
+void init_input_buf(const char *buf, unsigned long long size)
 {
 	input_buf = buf;
 	input_buf_siz = size;
@@ -338,7 +338,7 @@ void print_printk(void)
 	}
 }
 
-static struct event *alloc_event(void)
+struct event *alloc_event(void)
 {
 	struct event *event;
 
@@ -701,7 +701,7 @@ static int read_expected_item(enum event_type expect, const char *str)
 	return __read_expected(expect, str, 0, true);
 }
 
-static char *event_read_name(void)
+char *event_read_name(void)
 {
 	char *token;
 
@@ -721,7 +721,7 @@ static char *event_read_name(void)
 	return NULL;
 }
 
-static int event_read_id(void)
+int event_read_id(void)
 {
 	char *token;
 	int id;
@@ -986,7 +986,7 @@ fail_expect:
 	return -1;
 }
 
-static int event_read_format(struct event *event)
+int event_read_format(struct event *event)
 {
 	char *token;
 	int ret;
diff --git a/tools/perf/util/trace-event-read.c b/tools/lib/trace/event-read.c
similarity index 99%
rename from tools/perf/util/trace-event-read.c
rename to tools/lib/trace/event-read.c
index f55cc3a..f65dcaa 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/lib/trace/event-read.c
@@ -36,8 +36,8 @@
 #include <ctype.h>
 #include <errno.h>
 
-#include "../perf.h"
-#include "util.h"
+#include "../../perf/perf.h"
+#include "../../perf/util/util.h"
 #include "trace-event.h"
 
 static int input_fd;
diff --git a/tools/perf/util/trace-event.h b/tools/lib/trace/trace-event.h
similarity index 91%
rename from tools/perf/util/trace-event.h
rename to tools/lib/trace/trace-event.h
index f674dda..bf28476 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/lib/trace/trace-event.h
@@ -1,12 +1,13 @@
-#ifndef __PERF_TRACE_EVENTS_H
-#define __PERF_TRACE_EVENTS_H
+#ifndef __LIB_TRACE_EVENTS_H
+#define __LIB_TRACE_EVENTS_H
 
 #include <stdbool.h>
-#include "parse-events.h"
-#include "session.h"
+#include <linux/compiler.h>
 
-#define __unused __attribute__((unused))
+#include "../../perf/util/session.h"
+#include "../../perf/util/parse-events.h"
 
+#define __unused       __attribute__((unused))
 
 #ifndef PAGE_MASK
 #define PAGE_MASK (page_size - 1)
@@ -265,6 +266,15 @@ unsigned long long eval_flag(const char *flag);
 int read_tracing_data(int fd, struct list_head *pattrs);
 ssize_t read_tracing_data_size(int fd, struct list_head *pattrs);
 
+extern struct event *alloc_event(void);
+extern void init_input_buf(const char *buf, unsigned long long size);
+extern char *event_read_name(void);
+extern int event_read_id(void);
+extern int event_read_format(struct event *event);
+unsigned long get_filesize(const char *file);
+char *get_tracing_file(const char *name);
+void put_tracing_file(char *file);
+
 /* taken from kernel/trace/trace.h */
 enum trace_flag_type {
 	TRACE_FLAG_IRQS_OFF		= 0x01,
@@ -299,4 +309,4 @@ int common_pc(struct scripting_context *context);
 int common_flags(struct scripting_context *context);
 int common_lock_depth(struct scripting_context *context);
 
-#endif /* __PERF_TRACE_EVENTS_H */
+#endif /* __LIB_TRACE_EVENTS_H */
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index ab9f667..2c82f7f 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -124,7 +124,7 @@ endif
 # Those must not be GNU-specific; they are shared with perl/ which may
 # be built by a different compiler. (Note that this is an artifact now
 # but it still might be nice to keep that distinction.)
-BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include
+BASIC_CFLAGS += -Iutil/include -Iarch/$(ARCH)/include
 BASIC_LDFLAGS =
 
 # Guard against environment variables
@@ -133,6 +133,7 @@ LIB_H =
 LIB_OBJS =
 PYRF_OBJS =
 SCRIPT_SH =
+EXTRA_LIBS =
 
 SCRIPT_SH += perf-archive.sh
 
@@ -175,6 +176,8 @@ export PERL_PATH
 
 LIB_FILE=$(OUTPUT)libperf.a
 
+EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a
+
 LIB_H += ../../include/linux/perf_event.h
 LIB_H += ../../include/linux/rbtree.h
 LIB_H += ../../include/linux/list.h
@@ -238,7 +241,6 @@ LIB_H += util/sort.h
 LIB_H += util/hist.h
 LIB_H += util/thread.h
 LIB_H += util/thread_map.h
-LIB_H += util/trace-event.h
 LIB_H += util/probe-finder.h
 LIB_H += util/probe-event.h
 LIB_H += util/pstack.h
@@ -289,9 +291,6 @@ LIB_OBJS += $(OUTPUT)util/pstack.o
 LIB_OBJS += $(OUTPUT)util/session.o
 LIB_OBJS += $(OUTPUT)util/thread.o
 LIB_OBJS += $(OUTPUT)util/thread_map.o
-LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
-LIB_OBJS += $(OUTPUT)util/trace-event-read.o
-LIB_OBJS += $(OUTPUT)util/trace-event-info.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
 LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
@@ -334,7 +333,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
 BUILTIN_OBJS += $(OUTPUT)builtin-test.o
 BUILTIN_OBJS += $(OUTPUT)builtin-inject.o
 
-PERFLIBS = $(LIB_FILE)
+PERFLIBS = $(LIB_FILE) $(EXTRA_LIBS)
 
 # Files needed for the python binding, perf.so
 # pyrf is just an internal name needed for all those wrappers.
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
index f7781c6..0c7ee07 100644
--- a/tools/perf/bench/bench.h
+++ b/tools/perf/bench/bench.h
@@ -1,6 +1,8 @@
 #ifndef BENCH_H
 #define BENCH_H
 
+#include <linux/compiler.h>
+
 extern int bench_sched_messaging(int argc, const char **argv, const char *prefix);
 extern int bench_sched_pipe(int argc, const char **argv, const char *prefix);
 extern int bench_mem_memcpy(int argc, const char **argv, const char *prefix __used);
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 225e963..49062b6 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -9,7 +9,7 @@
 #include "util/session.h"
 
 #include "util/parse-options.h"
-#include "util/trace-event.h"
+#include <trace/trace-event.h>
 
 #include "util/debug.h"
 
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 34d1e85..1981fe4 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -9,7 +9,7 @@
 #include "util/session.h"
 
 #include "util/parse-options.h"
-#include "util/trace-event.h"
+#include <trace/trace-event.h>
 
 #include "util/debug.h"
 
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 9ac05aa..f73806f 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -8,7 +8,7 @@
 #include "util/header.h"
 
 #include "util/parse-options.h"
-#include "util/trace-event.h"
+#include <trace/trace-event.h>
 
 #include "util/debug.h"
 #include "util/session.h"
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index dcfe887..26fb319 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -9,7 +9,7 @@
 #include "util/session.h"
 
 #include "util/parse-options.h"
-#include "util/trace-event.h"
+#include <trace/trace-event.h>
 
 #include "util/debug.h"
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 974f6d3..f4c0d50 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -9,7 +9,7 @@
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/thread.h"
-#include "util/trace-event.h"
+#include <trace/trace-event.h>
 #include "util/parse-options.h"
 #include "util/util.h"
 #include "util/evlist.h"
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/Context.c b/tools/perf/scripts/perl/Perf-Trace-Util/Context.c
index 790ceba..bb52853 100644
--- a/tools/perf/scripts/perl/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/perl/Perf-Trace-Util/Context.c
@@ -32,7 +32,7 @@
 #include "perl.h"
 #include "XSUB.h"
 #include "../../../perf.h"
-#include "../../../util/trace-event.h"
+#include <trace/trace-event.h>
 
 #ifndef PERL_UNUSED_VAR
 #  define PERL_UNUSED_VAR(var) if (0) var = var
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
index 315067b..7621a46 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
@@ -21,7 +21,7 @@
 
 #include <Python.h>
 #include "../../../perf.h"
-#include "../../../util/trace-event.h"
+#include <trace/trace-event.h>
 
 PyMODINIT_FUNC initperf_trace_context(void);
 
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index fc5e5a0..ced8cee 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -5,6 +5,7 @@
 #include "util.h"
 #include "strbuf.h"
 #include "../perf.h"
+#include <linux/compiler.h>
 
 #define CMD_EXEC_PATH "--exec-path"
 #define CMD_PERF_DIR "--perf-dir="
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 93862a8..ac26a5c 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -13,7 +13,7 @@
 #include "util.h"
 #include "header.h"
 #include "../perf.h"
-#include "trace-event.h"
+#include <trace/trace-event.h>
 #include "session.h"
 #include "symbol.h"
 #include "debug.h"
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index f022316..9c074ea 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -44,7 +44,7 @@
 #include "symbol.h"
 #include "thread.h"
 #include "debugfs.h"
-#include "trace-event.h"	/* For __unused */
+#include <trace/trace-event.h>	/* For __unused */
 #include "probe-event.h"
 #include "probe-finder.h"
 
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index 74350ff..0c1ba9b 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -27,7 +27,7 @@
 
 #include "../../perf.h"
 #include "../util.h"
-#include "../trace-event.h"
+#include <trace/trace-event.h>
 
 #include <EXTERN.h>
 #include <perl.h>
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 6ccf70e..79caf91 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -29,7 +29,7 @@
 
 #include "../../perf.h"
 #include "../util.h"
-#include "../trace-event.h"
+#include <trace/trace-event.h>
 
 PyMODINIT_FUNC initperf_trace_context(void);
 
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index c9dcbec..205ec96 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -27,7 +27,7 @@
 
 #include "../perf.h"
 #include "util.h"
-#include "trace-event.h"
+#include <trace/trace-event.h>
 
 struct scripting_context *scripting_context;
 
diff --git a/tools/scripts/Makefile.lib b/tools/scripts/Makefile.lib
index 9dfa0f9..f6c6af6 100644
--- a/tools/scripts/Makefile.lib
+++ b/tools/scripts/Makefile.lib
@@ -1,5 +1,9 @@
 ifeq ("$(origin O)", "command line")
 	OUTPUT := $(O)/
+	LIB_OUTPUT := $(O)/generic-lib/
+	__dummy := $(shell if [ ! -d $(LIB_OUTPUT) ]; then mkdir -p $(LIB_OUTPUT); fi)
+else
+	LIB_OUTPUT := $(PERF_TOP_DIR)/lib/
 endif
 
 ifneq ($(OUTPUT),)
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 08/18] perf: Remove duplicate enum trace_flag_type
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (6 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 07/18] perf: Export trace-event utils Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 09/18] perf: Drop redundant FD macro definitions Borislav Petkov
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Merge the two definitions.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/lib/trace/trace-event.h  |   10 +++++++++-
 tools/perf/builtin-timechart.c |   21 ++-------------------
 2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/tools/lib/trace/trace-event.h b/tools/lib/trace/trace-event.h
index bf28476..8510207 100644
--- a/tools/lib/trace/trace-event.h
+++ b/tools/lib/trace/trace-event.h
@@ -275,7 +275,15 @@ unsigned long get_filesize(const char *file);
 char *get_tracing_file(const char *name);
 void put_tracing_file(char *file);
 
-/* taken from kernel/trace/trace.h */
+/*
+ * trace_flag_type is an enumeration that holds different
+ * states when a trace occurs. These are:
+ *  IRQS_OFF            - interrupts were disabled
+ *  IRQS_NOSUPPORT      - arch does not support irqs_disabled_flags
+ *  NEED_RESCED         - reschedule is requested
+ *  HARDIRQ             - inside an interrupt handler
+ *  SOFTIRQ             - inside a softirq handler
+ */
 enum trace_flag_type {
 	TRACE_FLAG_IRQS_OFF		= 0x01,
 	TRACE_FLAG_IRQS_NOSUPPORT	= 0x02,
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index aa26f4d..9782c9a 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -32,6 +32,8 @@
 #include "util/session.h"
 #include "util/svghelper.h"
 
+#include <trace/trace-event.h>
+
 #define SUPPORT_OLD_POWER_EVENTS 1
 #define PWR_EVENT_EXIT -1
 
@@ -330,25 +332,6 @@ struct wakeup_entry {
 	int   success;
 };
 
-/*
- * trace_flag_type is an enumeration that holds different
- * states when a trace occurs. These are:
- *  IRQS_OFF            - interrupts were disabled
- *  IRQS_NOSUPPORT      - arch does not support irqs_disabled_flags
- *  NEED_RESCED         - reschedule is requested
- *  HARDIRQ             - inside an interrupt handler
- *  SOFTIRQ             - inside a softirq handler
- */
-enum trace_flag_type {
-	TRACE_FLAG_IRQS_OFF		= 0x01,
-	TRACE_FLAG_IRQS_NOSUPPORT	= 0x02,
-	TRACE_FLAG_NEED_RESCHED		= 0x04,
-	TRACE_FLAG_HARDIRQ		= 0x08,
-	TRACE_FLAG_SOFTIRQ		= 0x10,
-};
-
-
-
 struct sched_switch {
 	struct trace_entry te;
 	char prev_comm[TASK_COMM_LEN];
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 09/18] perf: Drop redundant FD macro definitions
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (7 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 08/18] perf: Remove duplicate enum trace_flag_type Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-07-25 15:04   ` Arnaldo Carvalho de Melo
  2011-04-23 16:28 ` [PATCH 10/18] perf: Export debugfs utilities Borislav Petkov
                   ` (9 subsequent siblings)
  18 siblings, 1 reply; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Put a single define in the util/util.h header which should be generic
enough and included by all builtin commands.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/perf/builtin-record.c |    2 --
 tools/perf/builtin-top.c    |    2 --
 tools/perf/util/evlist.c    |    3 ---
 tools/perf/util/evsel.c     |    2 --
 tools/perf/util/util.h      |    3 +++
 5 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 4165382..4497a38 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -30,8 +30,6 @@
 #include <sched.h>
 #include <sys/mman.h>
 
-#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
-
 enum write_mode_t {
 	WRITE_FORCE,
 	WRITE_APPEND
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 7e3d6e3..7fd50c1 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -62,8 +62,6 @@
 #include <linux/unistd.h>
 #include <linux/types.h>
 
-#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
-
 static struct perf_top top = {
 	.count_filter		= 5,
 	.delay_secs		= 2,
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 45da8d1..65a8031 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -19,9 +19,6 @@
 #include <linux/bitops.h>
 #include <linux/hash.h>
 
-#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
-#define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
-
 void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
 		       struct thread_map *threads)
 {
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index d6fd59b..13ee267 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -13,8 +13,6 @@
 #include "cpumap.h"
 #include "thread_map.h"
 
-#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
-
 void perf_evsel__init(struct perf_evsel *evsel,
 		      struct perf_event_attr *attr, int idx)
 {
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index fc78428..c32d66d 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -39,6 +39,9 @@
 /* Approximation of the length of the decimal representation of this type. */
 #define decimal_length(x)	((int)(sizeof(x) * 2.56 + 0.5) + 1)
 
+#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
+#define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
+
 #define _ALL_SOURCE 1
 #define _GNU_SOURCE 1
 #define _BSD_SOURCE 1
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 10/18] perf: Export debugfs utilities
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (8 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 09/18] perf: Drop redundant FD macro definitions Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 11/18] perf: Export cpumap.[ch] Borislav Petkov
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Export /proc/mounts parser and other debugfs-related helpers for general
use.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/Makefile                                     |    9 ++++-
 tools/lib/lk/Makefile                              |   41 ++++++++++++++++++++
 tools/{perf/util => lib/lk}/debugfs.c              |    2 +-
 tools/{perf/util => lib/lk}/debugfs.h              |    7 ++-
 tools/{perf/util => lib/lk}/types.h                |    6 +-
 tools/{perf/util => lib/lk}/usage.c                |    0
 tools/{perf/util => lib/lk}/util.c                 |    2 +-
 tools/{perf/util => lib/lk}/util.h                 |    0
 tools/lib/perf/shared.h                            |    9 ++++
 tools/lib/trace/event-info.c                       |    2 +-
 tools/lib/trace/event-parse.c                      |    2 +-
 tools/lib/trace/event-read.c                       |    2 +-
 tools/perf/Makefile                                |    9 +----
 tools/perf/bench/mem-memcpy.c                      |    2 +-
 tools/perf/bench/sched-messaging.c                 |    2 +-
 tools/perf/bench/sched-pipe.c                      |    2 +-
 tools/perf/builtin-annotate.c                      |    4 +-
 tools/perf/builtin-bench.c                         |    2 +-
 tools/perf/builtin-diff.c                          |    2 +-
 tools/perf/builtin-evlist.c                        |    3 +-
 tools/perf/builtin-kmem.c                          |    2 +-
 tools/perf/builtin-kvm.c                           |    2 +-
 tools/perf/builtin-lock.c                          |    2 +-
 tools/perf/builtin-probe.c                         |    4 +-
 tools/perf/builtin-record.c                        |    2 +-
 tools/perf/builtin-report.c                        |    2 +-
 tools/perf/builtin-sched.c                         |    2 +-
 tools/perf/builtin-script.c                        |    2 +-
 tools/perf/builtin-stat.c                          |    2 +-
 tools/perf/builtin-timechart.c                     |    2 +-
 tools/perf/builtin-top.c                           |    2 +-
 tools/perf/builtin.h                               |    2 +-
 tools/perf/perf.c                                  |   21 +++++++---
 tools/perf/perf.h                                  |    2 +-
 tools/perf/util/annotate.c                         |    2 +-
 tools/perf/util/annotate.h                         |    2 +-
 tools/perf/util/build-id.c                         |    2 +-
 tools/perf/util/cache.h                            |    3 +-
 tools/perf/util/callchain.c                        |    2 +-
 tools/perf/util/cgroup.c                           |    4 +-
 tools/perf/util/config.c                           |    2 +-
 tools/perf/util/cpumap.c                           |    2 +-
 tools/perf/util/debug.c                            |    2 +-
 tools/perf/util/evlist.c                           |    2 +-
 tools/perf/util/evsel.c                            |    2 +-
 tools/perf/util/evsel.h                            |    2 +-
 tools/perf/util/header.c                           |    2 +-
 tools/perf/util/header.h                           |    2 +-
 tools/perf/util/hist.c                             |    2 +-
 tools/perf/util/include/linux/ctype.h              |    2 +-
 tools/perf/util/map.h                              |    2 +-
 tools/perf/util/parse-events.c                     |    4 +-
 tools/perf/util/parse-options.c                    |    2 +-
 tools/perf/util/probe-event.c                      |    4 +-
 tools/perf/util/probe-finder.c                     |    2 +-
 tools/perf/util/probe-finder.h                     |    2 +-
 tools/perf/util/pstack.c                           |    2 +-
 .../perf/util/scripting-engines/trace-event-perl.c |    2 +-
 .../util/scripting-engines/trace-event-python.c    |    2 +-
 tools/perf/util/session.c                          |    2 +-
 tools/perf/util/setup.py                           |    2 +-
 tools/perf/util/sort.h                             |    2 +-
 tools/perf/util/strfilter.c                        |    2 +-
 tools/perf/util/string.c                           |    2 +-
 tools/perf/util/svghelper.h                        |    2 +-
 tools/perf/util/thread.c                           |    2 +-
 tools/perf/util/top.h                              |    2 +-
 tools/perf/util/trace-event-scripting.c            |    2 +-
 tools/perf/util/ui/browser.c                       |    2 +-
 tools/perf/util/ui/browser.h                       |    2 +-
 tools/perf/util/ui/browsers/hists.c                |    2 +-
 tools/perf/util/values.c                           |    2 +-
 tools/perf/util/values.h                           |    2 +-
 tools/perf/util/xyarray.c                          |    2 +-
 74 files changed, 150 insertions(+), 94 deletions(-)
 create mode 100644 tools/lib/lk/Makefile
 rename tools/{perf/util => lib/lk}/debugfs.c (99%)
 rename tools/{perf/util => lib/lk}/debugfs.h (85%)
 rename tools/{perf/util => lib/lk}/types.h (83%)
 rename tools/{perf/util => lib/lk}/usage.c (100%)
 rename tools/{perf/util => lib/lk}/util.c (98%)
 rename tools/{perf/util => lib/lk}/util.h (100%)
 create mode 100644 tools/lib/perf/shared.h

diff --git a/tools/Makefile b/tools/Makefile
index 48f0720..f302177 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -9,12 +9,18 @@ BASIC_CFLAGS = -I$(CURDIR)/lib
 BASIC_CFLAGS += -I$(CURDIR)/perf/util/include
 export BASIC_CFLAGS
 
-perf: libtrace .FORCE
+PYRF_OBJS =
+export PYRF_OBJS
+
+perf: libtrace liblk .FORCE
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1)
 
 firewire: .FORCE
 	$(QUIET_SUBDIR0)firewire/ $(QUIET_SUBDIR1)
 
+liblk: .FORCE
+	$(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1)
+
 libtrace: .FORCE
 	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1)
 
@@ -36,6 +42,7 @@ x86_energy: .FORCE
 clean:
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)firewire/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)slub/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)power/x86/turbostat/ $(QUIET_SUBDIR1) clean
diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
new file mode 100644
index 0000000..b192853
--- /dev/null
+++ b/tools/lib/lk/Makefile
@@ -0,0 +1,41 @@
+include ../../scripts/Makefile.lib
+
+# guard against environment variables
+LIB_H=
+LIB_OBJS=
+
+LIB_H += debugfs.h
+LIB_H += util.h
+LIB_H += types.h
+
+LIB_OBJS += debugfs.o
+LIB_OBJS += usage.o
+LIB_OBJS += util.o
+
+PYRF_OBJS += util.o
+
+LIBFILE = $(LIB_OUTPUT)liblk.a
+
+CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
+EXTLIBS = -lpthread -lrt -lelf -lm
+ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+ALL_LDFLAGS = $(LDFLAGS)
+
+RM = rm -f
+
+$(LIBFILE): $(LIB_OBJS)
+	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
+
+$(LIB_OBJS): $(LIB_H)
+
+%.o: %.c
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
+%.s: %.c
+	$(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
+%.o: %.S
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
+
+clean:
+	$(RM) $(LIB_OBJS) $(LIBFILE)
+
+.PHONY: clean
diff --git a/tools/perf/util/debugfs.c b/tools/lib/lk/debugfs.c
similarity index 99%
rename from tools/perf/util/debugfs.c
rename to tools/lib/lk/debugfs.c
index a88fefc..569b6b2 100644
--- a/tools/perf/util/debugfs.c
+++ b/tools/lib/lk/debugfs.c
@@ -1,6 +1,6 @@
 #include "util.h"
 #include "debugfs.h"
-#include "cache.h"
+#include <perf/shared.h>
 
 static int debugfs_premounted;
 static char debugfs_mountpoint[MAX_PATH+1];
diff --git a/tools/perf/util/debugfs.h b/tools/lib/lk/debugfs.h
similarity index 85%
rename from tools/perf/util/debugfs.h
rename to tools/lib/lk/debugfs.h
index 83a0287..8d12a5b 100644
--- a/tools/perf/util/debugfs.h
+++ b/tools/lib/lk/debugfs.h
@@ -1,7 +1,8 @@
-#ifndef __DEBUGFS_H__
-#define __DEBUGFS_H__
+#ifndef __LK_DEBUGFS_H__
+#define __LK_DEBUGFS_H__
 
 #include <sys/mount.h>
+#include <sys/types.h>
 
 #ifndef MAX_PATH
 # define MAX_PATH 256
@@ -22,4 +23,4 @@ extern int debugfs_read(const char *entry, char *buffer, size_t size);
 extern void debugfs_force_cleanup(void);
 extern int debugfs_make_path(const char *element, char *buffer, int size);
 
-#endif /* __DEBUGFS_H__ */
+#endif /* __LK_DEBUGFS_H__ */
diff --git a/tools/perf/util/types.h b/tools/lib/lk/types.h
similarity index 83%
rename from tools/perf/util/types.h
rename to tools/lib/lk/types.h
index 5f3689a..587ebc8 100644
--- a/tools/perf/util/types.h
+++ b/tools/lib/lk/types.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_TYPES_H
-#define __PERF_TYPES_H
+#ifndef __LK_TYPES_H
+#define __LK_TYPES_H
 
 #include <stdint.h>
 
@@ -16,4 +16,4 @@ typedef signed short	   s16;
 typedef unsigned char	   u8;
 typedef signed char	   s8;
 
-#endif /* __PERF_TYPES_H */
+#endif /* __LK_TYPES_H */
diff --git a/tools/perf/util/usage.c b/tools/lib/lk/usage.c
similarity index 100%
rename from tools/perf/util/usage.c
rename to tools/lib/lk/usage.c
diff --git a/tools/perf/util/util.c b/tools/lib/lk/util.c
similarity index 98%
rename from tools/perf/util/util.c
rename to tools/lib/lk/util.c
index 5b3ea49..87c30b1 100644
--- a/tools/perf/util/util.c
+++ b/tools/lib/lk/util.c
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include <sys/mman.h>
 
 int mkdir_p(char *path, mode_t mode)
diff --git a/tools/perf/util/util.h b/tools/lib/lk/util.h
similarity index 100%
rename from tools/perf/util/util.h
rename to tools/lib/lk/util.h
diff --git a/tools/lib/perf/shared.h b/tools/lib/perf/shared.h
new file mode 100644
index 0000000..77344ff
--- /dev/null
+++ b/tools/lib/perf/shared.h
@@ -0,0 +1,9 @@
+#ifndef __PERF_SHARED_H
+#define __PERF_SHARED_H
+
+/*
+ * Common defines shared between perf and the libs
+ */
+#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
+
+#endif /* __PERF_SHARED_H */
diff --git a/tools/lib/trace/event-info.c b/tools/lib/trace/event-info.c
index 5270a64..dbc6ba9 100644
--- a/tools/lib/trace/event-info.c
+++ b/tools/lib/trace/event-info.c
@@ -39,7 +39,7 @@
 
 #include "../../perf/perf.h"
 #include "trace-event.h"
-#include "../perf/util/debugfs.h"
+#include <lk/debugfs.h>
 #include "../perf/util/evsel.h"
 
 #define VERSION "0.5"
diff --git a/tools/lib/trace/event-parse.c b/tools/lib/trace/event-parse.c
index 4a52cb8..da49703 100644
--- a/tools/lib/trace/event-parse.c
+++ b/tools/lib/trace/event-parse.c
@@ -30,7 +30,7 @@
 
 #undef _GNU_SOURCE
 #include "../../perf/perf.h"
-#include "../../perf/util/util.h"
+#include <lk/util.h>
 #include "trace-event.h"
 
 int header_page_ts_offset;
diff --git a/tools/lib/trace/event-read.c b/tools/lib/trace/event-read.c
index f65dcaa..1eda805 100644
--- a/tools/lib/trace/event-read.c
+++ b/tools/lib/trace/event-read.c
@@ -37,7 +37,7 @@
 #include <errno.h>
 
 #include "../../perf/perf.h"
-#include "../../perf/util/util.h"
+#include <lk/util.h>
 #include "trace-event.h"
 
 static int input_fd;
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 2c82f7f..692b1ad 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -176,7 +176,7 @@ export PERL_PATH
 
 LIB_FILE=$(OUTPUT)libperf.a
 
-EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a
+EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a $(LIB_OUTPUT)liblk.a
 
 LIB_H += ../../include/linux/perf_event.h
 LIB_H += ../../include/linux/rbtree.h
@@ -212,18 +212,15 @@ LIB_H += util/cache.h
 LIB_H += util/callchain.h
 LIB_H += util/build-id.h
 LIB_H += util/debug.h
-LIB_H += util/debugfs.h
 LIB_H += util/event.h
 LIB_H += util/evsel.h
 LIB_H += util/evlist.h
 LIB_H += util/exec_cmd.h
-LIB_H += util/types.h
 LIB_H += util/levenshtein.h
 LIB_H += util/map.h
 LIB_H += util/parse-options.h
 LIB_H += util/parse-events.h
 LIB_H += util/quote.h
-LIB_H += util/util.h
 LIB_H += util/xyarray.h
 LIB_H += util/header.h
 LIB_H += util/help.h
@@ -255,7 +252,6 @@ LIB_OBJS += $(OUTPUT)util/annotate.o
 LIB_OBJS += $(OUTPUT)util/build-id.o
 LIB_OBJS += $(OUTPUT)util/config.o
 LIB_OBJS += $(OUTPUT)util/ctype.o
-LIB_OBJS += $(OUTPUT)util/debugfs.o
 LIB_OBJS += $(OUTPUT)util/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
 LIB_OBJS += $(OUTPUT)util/evlist.o
@@ -276,7 +272,6 @@ LIB_OBJS += $(OUTPUT)util/string.o
 LIB_OBJS += $(OUTPUT)util/strlist.o
 LIB_OBJS += $(OUTPUT)util/strfilter.o
 LIB_OBJS += $(OUTPUT)util/top.o
-LIB_OBJS += $(OUTPUT)util/usage.o
 LIB_OBJS += $(OUTPUT)util/wrapper.o
 LIB_OBJS += $(OUTPUT)util/sigchain.o
 LIB_OBJS += $(OUTPUT)util/symbol.o
@@ -296,7 +291,6 @@ LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
 LIB_OBJS += $(OUTPUT)util/hist.o
 LIB_OBJS += $(OUTPUT)util/probe-event.o
-LIB_OBJS += $(OUTPUT)util/util.o
 LIB_OBJS += $(OUTPUT)util/xyarray.o
 LIB_OBJS += $(OUTPUT)util/cpumap.o
 LIB_OBJS += $(OUTPUT)util/cgroup.o
@@ -346,7 +340,6 @@ PYRF_OBJS += $(OUTPUT)util/evlist.o
 PYRF_OBJS += $(OUTPUT)util/evsel.o
 PYRF_OBJS += $(OUTPUT)util/python.o
 PYRF_OBJS += $(OUTPUT)util/thread_map.o
-PYRF_OBJS += $(OUTPUT)util/util.o
 PYRF_OBJS += $(OUTPUT)util/xyarray.o
 
 #
diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c
index db82021..96e0ff3 100644
--- a/tools/perf/bench/mem-memcpy.c
+++ b/tools/perf/bench/mem-memcpy.c
@@ -8,7 +8,7 @@
 #include <ctype.h>
 
 #include "../perf.h"
-#include "../util/util.h"
+#include <lk/util.h>
 #include "../util/parse-options.h"
 #include "../util/header.h"
 #include "bench.h"
diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c
index d1d1b30..37f12ad 100644
--- a/tools/perf/bench/sched-messaging.c
+++ b/tools/perf/bench/sched-messaging.c
@@ -10,7 +10,7 @@
  */
 
 #include "../perf.h"
-#include "../util/util.h"
+#include <lk/util.h>
 #include "../util/parse-options.h"
 #include "../builtin.h"
 #include "bench.h"
diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
index 0c7454f..3367404 100644
--- a/tools/perf/bench/sched-pipe.c
+++ b/tools/perf/bench/sched-pipe.c
@@ -11,7 +11,7 @@
  */
 
 #include "../perf.h"
-#include "../util/util.h"
+#include <lk/util.h>
 #include "../util/parse-options.h"
 #include "../builtin.h"
 #include "bench.h"
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index e18eb7e..2003f27 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -7,9 +7,9 @@
  */
 #include "builtin.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/color.h"
 #include <linux/list.h>
 #include "util/cache.h"
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index fcb9626..4ae8ea2 100644
--- a/tools/perf/builtin-bench.c
+++ b/tools/perf/builtin-bench.c
@@ -17,7 +17,7 @@
  */
 
 #include "perf.h"
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/parse-options.h"
 #include "builtin.h"
 #include "bench/bench.h"
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index e821999..7005bdf 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -12,7 +12,7 @@
 #include "util/session.h"
 #include "util/sort.h"
 #include "util/symbol.h"
-#include "util/util.h"
+#include <lk/util.h>
 
 #include <stdlib.h>
 
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index 4c5e9e0..356573c 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -4,8 +4,7 @@
  */
 #include "builtin.h"
 
-#include "util/util.h"
-
+#include <lk/util.h>
 #include <linux/list.h>
 
 #include "perf.h"
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 49062b6..47b50ec 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -1,7 +1,7 @@
 #include "builtin.h"
 #include "perf.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 1981fe4..e09ed03 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1,7 +1,7 @@
 #include "builtin.h"
 #include "perf.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index f73806f..cdadb47 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -1,7 +1,7 @@
 #include "builtin.h"
 #include "perf.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 2c0e64d..21e199a 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -34,12 +34,12 @@
 #undef _GNU_SOURCE
 #include "perf.h"
 #include "builtin.h"
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/strlist.h"
 #include "util/strfilter.h"
 #include "util/symbol.h"
 #include "util/debug.h"
-#include "util/debugfs.h"
+#include <lk/debugfs.h>
 #include "util/parse-options.h"
 #include "util/probe-finder.h"
 #include "util/probe-event.h"
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 4497a38..9ebfc4d 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -12,7 +12,7 @@
 #include "perf.h"
 
 #include "util/build-id.h"
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 498c6f7..876d3e2 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -7,7 +7,7 @@
  */
 #include "builtin.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 
 #include "util/annotate.h"
 #include "util/color.h"
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 26fb319..b56426a 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1,7 +1,7 @@
 #include "builtin.h"
 #include "perf.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index f4c0d50..8ff8e1b 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -11,7 +11,7 @@
 #include "util/thread.h"
 #include <trace/trace-event.h>
 #include "util/parse-options.h"
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/evlist.h"
 #include "util/evsel.h"
 
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 03f0e45..8a9b057 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -39,7 +39,7 @@
 
 #include "perf.h"
 #include "builtin.h"
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 #include "util/event.h"
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 9782c9a..27283c5 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -14,7 +14,7 @@
 
 #include "builtin.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 
 #include "util/color.h"
 #include <linux/list.h>
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 7fd50c1..22f4528 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -30,7 +30,7 @@
 #include "util/thread.h"
 #include "util/thread_map.h"
 #include "util/top.h"
-#include "util/util.h"
+#include <lk/util.h>
 #include <linux/rbtree.h>
 #include "util/parse-options.h"
 #include "util/parse-events.h"
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index 4702e24..a34c6b5 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -1,7 +1,7 @@
 #ifndef BUILTIN_H
 #define BUILTIN_H
 
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/strbuf.h"
 
 extern const char perf_version_string[];
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index ec635b7..9b47067 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -13,7 +13,8 @@
 #include "util/quote.h"
 #include "util/run-command.h"
 #include "util/parse-events.h"
-#include "util/debugfs.h"
+#include <lk/debugfs.h>
+#include <perf/shared.h>
 
 const char perf_usage_string[] =
 	"perf [--version] [--help] COMMAND [ARGS]";
@@ -417,14 +418,17 @@ static int run_argv(int *argcp, const char ***argv)
 }
 
 /* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
-static void get_debugfs_mntpt(void)
+static bool get_debugfs_mntpt(void)
 {
 	const char *path = debugfs_mount(NULL);
 
-	if (path)
+	if (path) {
 		strncpy(debugfs_mntpt, path, sizeof(debugfs_mntpt));
-	else
-		debugfs_mntpt[0] = '\0';
+		return true;
+	}
+
+	debugfs_mntpt[0] = '\0';
+	return false;
 }
 
 int main(int argc, const char **argv)
@@ -434,8 +438,11 @@ int main(int argc, const char **argv)
 	cmd = perf_extract_argv0_path(argv[0]);
 	if (!cmd)
 		cmd = "perf-help";
-	/* get debugfs mount point from /proc/mounts */
-	get_debugfs_mntpt();
+
+	/* Establish a debugfs mountpoint */
+	if (!get_debugfs_mntpt())
+		die("cannot find valid debugfs mountpoint");
+
 	/*
 	 * "perf-xxxx" is the same as "perf xxxx", but we obviously:
 	 *
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index a5fc660..7078b4f 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -91,7 +91,7 @@ void get_term_dimensions(struct winsize *ws);
 #include <sys/syscall.h>
 
 #include "../../include/linux/perf_event.h"
-#include "util/types.h"
+#include <lk/types.h>
 #include <stdbool.h>
 
 struct perf_mmap {
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index e01af2b..e9f5d02 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -7,7 +7,7 @@
  * Released under the GPL v2. (and only v2, not any later version)
  */
 
-#include "util.h"
+#include <lk/util.h>
 #include "build-id.h"
 #include "color.h"
 #include "cache.h"
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index c2c2868..b139a25 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -2,7 +2,7 @@
 #define __PERF_ANNOTATE_H
 
 #include <stdbool.h>
-#include "types.h"
+#include <lk/types.h>
 #include "symbol.h"
 #include <linux/list.h>
 #include <linux/rbtree.h>
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index a91cd99..1a381a4 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -6,7 +6,7 @@
  * Copyright (C) 2009, 2010 Red Hat Inc.
  * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <acme@redhat.com>
  */
-#include "util.h"
+#include <lk/util.h>
 #include <stdio.h>
 #include "build-id.h"
 #include "event.h"
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index ced8cee..02d764b 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -2,7 +2,7 @@
 #define __PERF_CACHE_H
 
 #include <stdbool.h>
-#include "util.h"
+#include <lk/util.h>
 #include "strbuf.h"
 #include "../perf.h"
 #include <linux/compiler.h>
@@ -16,7 +16,6 @@
 #define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
 #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
 #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
-#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int perf_default_config(const char *, const char *, void *);
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 9f7106a..c5fad20 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -15,7 +15,7 @@
 #include <errno.h>
 #include <math.h>
 
-#include "util.h"
+#include <lk/util.h>
 #include "callchain.h"
 
 bool ip_callchain__valid(struct ip_callchain *chain,
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 96bee5c..99267b3 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -1,9 +1,9 @@
-#include "util.h"
+#include <lk/util.h>
 #include "../perf.h"
 #include "parse-options.h"
 #include "evsel.h"
 #include "cgroup.h"
-#include "debugfs.h" /* MAX_PATH, STR() */
+#include <lk/debugfs.h> /* MAX_PATH, STR() */
 #include "evlist.h"
 
 int nr_cgroups;
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index e02d78c..bb2f5a0 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -5,7 +5,7 @@
  * Copyright (C) Johannes Schindelin, 2005
  *
  */
-#include "util.h"
+#include <lk/util.h>
 #include "cache.h"
 #include "exec_cmd.h"
 
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 6893eec..02755d5 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include "../perf.h"
 #include "cpumap.h"
 #include <assert.h>
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 155749d..45dfab7 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -10,7 +10,7 @@
 #include "color.h"
 #include "event.h"
 #include "debug.h"
-#include "util.h"
+#include <lk/util.h>
 
 int verbose;
 bool dump_trace = false, quiet = false;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 65a8031..7a270ed 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -11,8 +11,8 @@
 #include "thread_map.h"
 #include "evlist.h"
 #include "evsel.h"
-#include "util.h"
 #include "debug.h"
+#include <lk/util.h>
 
 #include <sys/mman.h>
 
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 13ee267..e76773c 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -9,7 +9,7 @@
 
 #include "evsel.h"
 #include "evlist.h"
-#include "util.h"
+#include <lk/util.h>
 #include "cpumap.h"
 #include "thread_map.h"
 
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index f79bb2c..526deed 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -4,7 +4,7 @@
 #include <linux/list.h>
 #include <stdbool.h>
 #include "../../../include/linux/perf_event.h"
-#include "types.h"
+#include <lk/types.h>
 #include "xyarray.h"
 #include "cgroup.h"
 #include "hist.h"
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index ac26a5c..4c89af6 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -10,7 +10,7 @@
 
 #include "evlist.h"
 #include "evsel.h"
-#include "util.h"
+#include <lk/util.h>
 #include "header.h"
 #include "../perf.h"
 #include <trace/trace-event.h>
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 456661d..418f488 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -4,7 +4,7 @@
 #include "../../../include/linux/perf_event.h"
 #include <sys/types.h>
 #include <stdbool.h>
-#include "types.h"
+#include <lk/types.h>
 #include "event.h"
 
 #include <linux/bitmap.h>
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 627a02e..b3a16a3 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1,5 +1,5 @@
 #include "annotate.h"
-#include "util.h"
+#include <lk/util.h>
 #include "build-id.h"
 #include "hist.h"
 #include "session.h"
diff --git a/tools/perf/util/include/linux/ctype.h b/tools/perf/util/include/linux/ctype.h
index a53d4ee..0698f26 100644
--- a/tools/perf/util/include/linux/ctype.h
+++ b/tools/perf/util/include/linux/ctype.h
@@ -1 +1 @@
-#include "../util.h"
+#include <lk/util.h>
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index b397c03..7e78d8b 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -6,7 +6,7 @@
 #include <linux/rbtree.h>
 #include <stdio.h>
 #include <stdbool.h>
-#include "types.h"
+#include <lk/types.h>
 
 enum map_type {
 	MAP__FUNCTION = 0,
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 952b4ae..18f2d1c 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1,5 +1,5 @@
 #include "../../../include/linux/hw_breakpoint.h"
-#include "util.h"
+#include <lk/util.h>
 #include "../perf.h"
 #include "evlist.h"
 #include "evsel.h"
@@ -10,7 +10,7 @@
 #include "symbol.h"
 #include "cache.h"
 #include "header.h"
-#include "debugfs.h"
+#include <lk/debugfs.h>
 
 struct event_symbol {
 	u8		type;
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 99d02aa..25b57fc 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include "parse-options.h"
 #include "cache.h"
 
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 9c074ea..b815435 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -34,7 +34,7 @@
 #include <elf.h>
 
 #undef _GNU_SOURCE
-#include "util.h"
+#include <lk/util.h>
 #include "event.h"
 #include "string.h"
 #include "strlist.h"
@@ -43,7 +43,7 @@
 #include "color.h"
 #include "symbol.h"
 #include "thread.h"
-#include "debugfs.h"
+#include <lk/debugfs.h>
 #include <trace/trace-event.h>	/* For __unused */
 #include "probe-event.h"
 #include "probe-finder.h"
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index a7c7145..bc1ef2ad 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -36,7 +36,7 @@
 #include <linux/bitops.h>
 #include "event.h"
 #include "debug.h"
-#include "util.h"
+#include <lk/util.h>
 #include "symbol.h"
 #include "probe-finder.h"
 
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index 605730a..717b487 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -2,7 +2,7 @@
 #define _PROBE_FINDER_H
 
 #include <stdbool.h>
-#include "util.h"
+#include <lk/util.h>
 #include "probe-event.h"
 
 #define MAX_PATH_LEN		 256
diff --git a/tools/perf/util/pstack.c b/tools/perf/util/pstack.c
index 13d36fa..aacedb8 100644
--- a/tools/perf/util/pstack.c
+++ b/tools/perf/util/pstack.c
@@ -4,7 +4,7 @@
  * (c) 2010 Arnaldo Carvalho de Melo <acme@redhat.com>
  */
 
-#include "util.h"
+#include <lk/util.h>
 #include "pstack.h"
 #include <linux/kernel.h>
 #include <stdlib.h>
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index 0c1ba9b..0cbf11c 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -26,7 +26,7 @@
 #include <errno.h>
 
 #include "../../perf.h"
-#include "../util.h"
+#include <lk/util.h>
 #include <trace/trace-event.h>
 
 #include <EXTERN.h>
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 79caf91..c8e6d35 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -28,7 +28,7 @@
 #include <errno.h>
 
 #include "../../perf.h"
-#include "../util.h"
+#include <lk/util.h>
 #include <trace/trace-event.h>
 
 PyMODINIT_FUNC initperf_trace_context(void);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index fff6674..46c80de 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -11,7 +11,7 @@
 #include "evsel.h"
 #include "session.h"
 #include "sort.h"
-#include "util.h"
+#include <lk/util.h>
 
 static int perf_session__open(struct perf_session *self, bool force)
 {
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index bbc982f..78a9b98 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -9,7 +9,7 @@ cflags += getenv('CFLAGS', '').split()
 perf = Extension('perf',
 		  sources = ['util/python.c', 'util/ctype.c', 'util/evlist.c',
 			     'util/evsel.c', 'util/cpumap.c', 'util/thread_map.c',
-			     'util/util.c', 'util/xyarray.c', 'util/cgroup.c'],
+			     '../lib/lk/util.c', 'util/xyarray.c', 'util/cgroup.c'],
 		  include_dirs = ['util/include'],
 		  extra_compile_args = cflags,
                  )
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 0b91053..ecfd0c6 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -2,7 +2,7 @@
 #define __PERF_SORT_H
 #include "../builtin.h"
 
-#include "util.h"
+#include <lk/util.h>
 
 #include "color.h"
 #include <linux/list.h>
diff --git a/tools/perf/util/strfilter.c b/tools/perf/util/strfilter.c
index 834c8eb..3d4939d 100644
--- a/tools/perf/util/strfilter.c
+++ b/tools/perf/util/strfilter.c
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include "string.h"
 #include "strfilter.h"
 
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index b9a985d..109e486 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include "string.h"
 
 #define K 1024LL
diff --git a/tools/perf/util/svghelper.h b/tools/perf/util/svghelper.h
index e078198..ac74b40 100644
--- a/tools/perf/util/svghelper.h
+++ b/tools/perf/util/svghelper.h
@@ -1,7 +1,7 @@
 #ifndef __PERF_SVGHELPER_H
 #define __PERF_SVGHELPER_H
 
-#include "types.h"
+#include <lk/types.h>
 
 extern void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end);
 extern void svg_box(int Yslot, u64 start, u64 end, const char *type);
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index d5d3b22..604d3c7 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -4,7 +4,7 @@
 #include <string.h>
 #include "session.h"
 #include "thread.h"
-#include "util.h"
+#include <lk/util.h>
 #include "debug.h"
 
 static struct thread *thread__new(pid_t pid)
diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h
index bfbf95b..180b1cb8 100644
--- a/tools/perf/util/top.h
+++ b/tools/perf/util/top.h
@@ -1,7 +1,7 @@
 #ifndef __PERF_TOP_H
 #define __PERF_TOP_H 1
 
-#include "types.h"
+#include <lk/types.h>
 #include "../perf.h"
 #include <stddef.h>
 #include <pthread.h>
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index 205ec96..f9b8950 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -26,7 +26,7 @@
 #include <errno.h>
 
 #include "../perf.h"
-#include "util.h"
+#include <lk/util.h>
 #include <trace/trace-event.h>
 
 struct scripting_context *scripting_context;
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c
index 611219f..036bb5c 100644
--- a/tools/perf/util/ui/browser.c
+++ b/tools/perf/util/ui/browser.c
@@ -8,7 +8,7 @@
 #include "browser.h"
 #include "helpline.h"
 #include "../color.h"
-#include "../util.h"
+#include <lk/util.h>
 #include <stdio.h>
 
 static int ui_browser__percent_color(double percent, bool current)
diff --git a/tools/perf/util/ui/browser.h b/tools/perf/util/ui/browser.h
index fc63dda..4b5834c 100644
--- a/tools/perf/util/ui/browser.h
+++ b/tools/perf/util/ui/browser.h
@@ -4,7 +4,7 @@
 #include <stdbool.h>
 #include <newt.h>
 #include <sys/types.h>
-#include "../types.h"
+#include <lk/types.h>
 
 #define HE_COLORSET_TOP		50
 #define HE_COLORSET_MEDIUM	51
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c
index 5d767c6..453aad2 100644
--- a/tools/perf/util/ui/browsers/hists.c
+++ b/tools/perf/util/ui/browsers/hists.c
@@ -12,7 +12,7 @@
 #include "../../hist.h"
 #include "../../pstack.h"
 #include "../../sort.h"
-#include "../../util.h"
+#include <lk/util.h>
 
 #include "../browser.h"
 #include "../helpline.h"
diff --git a/tools/perf/util/values.c b/tools/perf/util/values.c
index bdd3347..f544f92 100644
--- a/tools/perf/util/values.c
+++ b/tools/perf/util/values.c
@@ -1,6 +1,6 @@
 #include <stdlib.h>
 
-#include "util.h"
+#include <lk/util.h>
 #include "values.h"
 
 void perf_read_values_init(struct perf_read_values *values)
diff --git a/tools/perf/util/values.h b/tools/perf/util/values.h
index 2fa967e..f762cb7 100644
--- a/tools/perf/util/values.h
+++ b/tools/perf/util/values.h
@@ -1,7 +1,7 @@
 #ifndef __PERF_VALUES_H
 #define __PERF_VALUES_H
 
-#include "types.h"
+#include <lk/types.h>
 
 struct perf_read_values {
 	int threads;
diff --git a/tools/perf/util/xyarray.c b/tools/perf/util/xyarray.c
index 22afbf6..979a90f 100644
--- a/tools/perf/util/xyarray.c
+++ b/tools/perf/util/xyarray.c
@@ -1,5 +1,5 @@
 #include "xyarray.h"
-#include "util.h"
+#include <lk/util.h>
 
 struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
 {
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 11/18] perf: Export cpumap.[ch]
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (9 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 10/18] perf: Export debugfs utilities Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 12/18] perf: Export thread_map.[ch] Borislav Petkov
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Put it into the generic part of the lib since it is tool-agnostic.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/lib/lk/Makefile                |    3 +++
 tools/{perf/util => lib/lk}/cpumap.c |    2 +-
 tools/{perf/util => lib/lk}/cpumap.h |    6 +++---
 tools/perf/Makefile                  |    4 ----
 tools/perf/builtin-record.c          |    2 +-
 tools/perf/builtin-stat.c            |    2 +-
 tools/perf/builtin-test.c            |    2 +-
 tools/perf/builtin-top.c             |    2 +-
 tools/perf/util/evlist.c             |    2 +-
 tools/perf/util/evsel.c              |    2 +-
 tools/perf/util/python.c             |    2 +-
 tools/perf/util/setup.py             |    4 ++--
 tools/perf/util/top.c                |    2 +-
 13 files changed, 17 insertions(+), 18 deletions(-)
 rename tools/{perf/util => lib/lk}/cpumap.c (99%)
 rename tools/{perf/util => lib/lk}/cpumap.h (70%)

diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
index b192853..49f7a64 100644
--- a/tools/lib/lk/Makefile
+++ b/tools/lib/lk/Makefile
@@ -7,12 +7,15 @@ LIB_OBJS=
 LIB_H += debugfs.h
 LIB_H += util.h
 LIB_H += types.h
+LIB_H += cpumap.h
 
 LIB_OBJS += debugfs.o
 LIB_OBJS += usage.o
 LIB_OBJS += util.o
+LIB_OBJS += cpumap.o
 
 PYRF_OBJS += util.o
+PYRF_OBJS += cpumap.o
 
 LIBFILE = $(LIB_OUTPUT)liblk.a
 
diff --git a/tools/perf/util/cpumap.c b/tools/lib/lk/cpumap.c
similarity index 99%
rename from tools/perf/util/cpumap.c
rename to tools/lib/lk/cpumap.c
index 02755d5..85a5d38 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/lib/lk/cpumap.c
@@ -1,5 +1,5 @@
 #include <lk/util.h>
-#include "../perf.h"
+#include "../../perf/perf.h"
 #include "cpumap.h"
 #include <assert.h>
 #include <stdio.h>
diff --git a/tools/perf/util/cpumap.h b/tools/lib/lk/cpumap.h
similarity index 70%
rename from tools/perf/util/cpumap.h
rename to tools/lib/lk/cpumap.h
index 072c0a3..9558051 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/lib/lk/cpumap.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_CPUMAP_H
-#define __PERF_CPUMAP_H
+#ifndef __LK_CPUMAP_H
+#define __LK_CPUMAP_H
 
 struct cpu_map {
 	int nr;
@@ -10,4 +10,4 @@ struct cpu_map *cpu_map__new(const char *cpu_list);
 struct cpu_map *cpu_map__dummy_new(void);
 void cpu_map__delete(struct cpu_map *map);
 
-#endif /* __PERF_CPUMAP_H */
+#endif /* __LK_CPUMAP_H */
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 692b1ad..44688ce 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -131,7 +131,6 @@ BASIC_LDFLAGS =
 BUILTIN_OBJS =
 LIB_H =
 LIB_OBJS =
-PYRF_OBJS =
 SCRIPT_SH =
 EXTRA_LIBS =
 
@@ -241,7 +240,6 @@ LIB_H += util/thread_map.h
 LIB_H += util/probe-finder.h
 LIB_H += util/probe-event.h
 LIB_H += util/pstack.h
-LIB_H += util/cpumap.h
 LIB_H += util/top.h
 LIB_H += $(ARCH_INCLUDE)
 LIB_H += util/cgroup.h
@@ -292,7 +290,6 @@ LIB_OBJS += $(OUTPUT)util/sort.o
 LIB_OBJS += $(OUTPUT)util/hist.o
 LIB_OBJS += $(OUTPUT)util/probe-event.o
 LIB_OBJS += $(OUTPUT)util/xyarray.o
-LIB_OBJS += $(OUTPUT)util/cpumap.o
 LIB_OBJS += $(OUTPUT)util/cgroup.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
@@ -334,7 +331,6 @@ PERFLIBS = $(LIB_FILE) $(EXTRA_LIBS)
 # This has to be in sync with what is in the 'sources' variable in
 # tools/perf/util/setup.py
 
-PYRF_OBJS += $(OUTPUT)util/cpumap.o
 PYRF_OBJS += $(OUTPUT)util/ctype.o
 PYRF_OBJS += $(OUTPUT)util/evlist.o
 PYRF_OBJS += $(OUTPUT)util/evsel.o
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 9ebfc4d..2f0bf69 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -23,7 +23,7 @@
 #include "util/debug.h"
 #include "util/session.h"
 #include "util/symbol.h"
-#include "util/cpumap.h"
+#include <lk/cpumap.h>
 #include "util/thread_map.h"
 
 #include <unistd.h>
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 8a9b057..9e0ae80 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -47,7 +47,7 @@
 #include "util/evsel.h"
 #include "util/debug.h"
 #include "util/header.h"
-#include "util/cpumap.h"
+#include <lk/cpumap.h>
 #include "util/thread.h"
 #include "util/thread_map.h"
 
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 11e3c84..2674fd6 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -235,7 +235,7 @@ out:
 	return err;
 }
 
-#include "util/cpumap.h"
+#include <lk/cpumap.h>
 #include "util/evsel.h"
 #include <sys/types.h>
 
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 22f4528..1c5626d 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -34,7 +34,7 @@
 #include <linux/rbtree.h>
 #include "util/parse-options.h"
 #include "util/parse-events.h"
-#include "util/cpumap.h"
+#include <lk/cpumap.h>
 #include "util/xyarray.h"
 
 #include "util/debug.h"
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 7a270ed..ed16c89 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -7,7 +7,7 @@
  * Released under the GPL v2. (and only v2, not any later version)
  */
 #include <poll.h>
-#include "cpumap.h"
+#include <lk/cpumap.h>
 #include "thread_map.h"
 #include "evlist.h"
 #include "evsel.h"
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index e76773c..6dca3e6 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -10,7 +10,7 @@
 #include "evsel.h"
 #include "evlist.h"
 #include <lk/util.h>
-#include "cpumap.h"
+#include <lk/cpumap.h>
 #include "thread_map.h"
 
 void perf_evsel__init(struct perf_evsel *evsel,
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index f5e3845..14d2006 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -5,7 +5,7 @@
 #include "evlist.h"
 #include "evsel.h"
 #include "event.h"
-#include "cpumap.h"
+#include <lk/cpumap.h>
 #include "thread_map.h"
 
 /* Define PyVarObject_HEAD_INIT for python 2.5 */
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 78a9b98..9e25da0 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -8,9 +8,9 @@ cflags += getenv('CFLAGS', '').split()
 
 perf = Extension('perf',
 		  sources = ['util/python.c', 'util/ctype.c', 'util/evlist.c',
-			     'util/evsel.c', 'util/cpumap.c', 'util/thread_map.c',
+			     'util/evsel.c', '../lib/lk/cpumap.c', 'util/thread_map.c',
 			     '../lib/lk/util.c', 'util/xyarray.c', 'util/cgroup.c'],
-		  include_dirs = ['util/include'],
+		  include_dirs = ['util/include', '../lib'],
 		  extra_compile_args = cflags,
                  )
 
diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c
index a11f607..0b027aa 100644
--- a/tools/perf/util/top.c
+++ b/tools/perf/util/top.c
@@ -6,7 +6,7 @@
  * Released under the GPL v2. (and only v2, not any later version)
  */
 
-#include "cpumap.h"
+#include <lk/cpumap.h>
 #include "event.h"
 #include "evlist.h"
 #include "evsel.h"
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 12/18] perf: Export thread_map.[ch]
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (10 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 11/18] perf: Export cpumap.[ch] Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 13/18] perf: Export evsel.[ch] Borislav Petkov
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Export into generic code since tool-agnostic and reusable.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/lib/lk/Makefile                    |    3 +++
 tools/{perf/util => lib/lk}/thread_map.c |    0
 tools/{perf/util => lib/lk}/thread_map.h |    6 +++---
 tools/perf/Makefile                      |    3 ---
 tools/perf/builtin-record.c              |    2 +-
 tools/perf/builtin-stat.c                |    2 +-
 tools/perf/builtin-test.c                |    2 +-
 tools/perf/builtin-top.c                 |    2 +-
 tools/perf/util/event.c                  |    2 +-
 tools/perf/util/evlist.c                 |    2 +-
 tools/perf/util/evsel.c                  |    2 +-
 tools/perf/util/python.c                 |    2 +-
 tools/perf/util/setup.py                 |    2 +-
 13 files changed, 15 insertions(+), 15 deletions(-)
 rename tools/{perf/util => lib/lk}/thread_map.c (100%)
 rename tools/{perf/util => lib/lk}/thread_map.h (76%)

diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
index 49f7a64..e3c5282 100644
--- a/tools/lib/lk/Makefile
+++ b/tools/lib/lk/Makefile
@@ -8,14 +8,17 @@ LIB_H += debugfs.h
 LIB_H += util.h
 LIB_H += types.h
 LIB_H += cpumap.h
+LIB_H += thread_map.h
 
 LIB_OBJS += debugfs.o
 LIB_OBJS += usage.o
 LIB_OBJS += util.o
 LIB_OBJS += cpumap.o
+LIB_OBJS += thread_map.o
 
 PYRF_OBJS += util.o
 PYRF_OBJS += cpumap.o
+PYRF_OBJS += thread_map.o
 
 LIBFILE = $(LIB_OUTPUT)liblk.a
 
diff --git a/tools/perf/util/thread_map.c b/tools/lib/lk/thread_map.c
similarity index 100%
rename from tools/perf/util/thread_map.c
rename to tools/lib/lk/thread_map.c
diff --git a/tools/perf/util/thread_map.h b/tools/lib/lk/thread_map.h
similarity index 76%
rename from tools/perf/util/thread_map.h
rename to tools/lib/lk/thread_map.h
index 3cb9073..9c88019 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/lib/lk/thread_map.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_THREAD_MAP_H
-#define __PERF_THREAD_MAP_H
+#ifndef __LK_THREAD_MAP_H
+#define __LK_THREAD_MAP_H
 
 #include <sys/types.h>
 
@@ -12,4 +12,4 @@ struct thread_map *thread_map__new_by_pid(pid_t pid);
 struct thread_map *thread_map__new_by_tid(pid_t tid);
 struct thread_map *thread_map__new(pid_t pid, pid_t tid);
 void thread_map__delete(struct thread_map *threads);
-#endif	/* __PERF_THREAD_MAP_H */
+#endif	/* __LK_THREAD_MAP_H */
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 44688ce..05c4eef 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -236,7 +236,6 @@ LIB_H += util/values.h
 LIB_H += util/sort.h
 LIB_H += util/hist.h
 LIB_H += util/thread.h
-LIB_H += util/thread_map.h
 LIB_H += util/probe-finder.h
 LIB_H += util/probe-event.h
 LIB_H += util/pstack.h
@@ -283,7 +282,6 @@ LIB_OBJS += $(OUTPUT)util/map.o
 LIB_OBJS += $(OUTPUT)util/pstack.o
 LIB_OBJS += $(OUTPUT)util/session.o
 LIB_OBJS += $(OUTPUT)util/thread.o
-LIB_OBJS += $(OUTPUT)util/thread_map.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
 LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
@@ -335,7 +333,6 @@ PYRF_OBJS += $(OUTPUT)util/ctype.o
 PYRF_OBJS += $(OUTPUT)util/evlist.o
 PYRF_OBJS += $(OUTPUT)util/evsel.o
 PYRF_OBJS += $(OUTPUT)util/python.o
-PYRF_OBJS += $(OUTPUT)util/thread_map.o
 PYRF_OBJS += $(OUTPUT)util/xyarray.o
 
 #
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 2f0bf69..7011ef3 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -24,7 +24,7 @@
 #include "util/session.h"
 #include "util/symbol.h"
 #include <lk/cpumap.h>
-#include "util/thread_map.h"
+#include <lk/thread_map.h>
 
 #include <unistd.h>
 #include <sched.h>
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 9e0ae80..e2d57dd 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -49,7 +49,7 @@
 #include "util/header.h"
 #include <lk/cpumap.h>
 #include "util/thread.h"
-#include "util/thread_map.h"
+#include <lk/thread_map.h>
 
 #include <sys/prctl.h>
 #include <math.h>
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 2674fd6..e471fe9 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -11,7 +11,7 @@
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 #include "util/symbol.h"
-#include "util/thread_map.h"
+#include <lk/thread_map.h>
 
 static long page_size;
 
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 1c5626d..2cd2e8c 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -28,7 +28,7 @@
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/thread.h"
-#include "util/thread_map.h"
+#include <lk/thread_map.h>
 #include "util/top.h"
 #include <lk/util.h>
 #include <linux/rbtree.h>
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 1023f67..922f9c6 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -6,7 +6,7 @@
 #include "string.h"
 #include "strlist.h"
 #include "thread.h"
-#include "thread_map.h"
+#include <lk/thread_map.h>
 
 static const char *perf_event__names[] = {
 	[0]			 = "TOTAL",
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index ed16c89..1f35fec 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -8,7 +8,7 @@
  */
 #include <poll.h>
 #include <lk/cpumap.h>
-#include "thread_map.h"
+#include <lk/thread_map.h>
 #include "evlist.h"
 #include "evsel.h"
 #include "debug.h"
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 6dca3e6..3a63422 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -11,7 +11,7 @@
 #include "evlist.h"
 #include <lk/util.h>
 #include <lk/cpumap.h>
-#include "thread_map.h"
+#include <lk/thread_map.h>
 
 void perf_evsel__init(struct perf_evsel *evsel,
 		      struct perf_event_attr *attr, int idx)
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 14d2006..756f50c 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -6,7 +6,7 @@
 #include "evsel.h"
 #include "event.h"
 #include <lk/cpumap.h>
-#include "thread_map.h"
+#include <lk/thread_map.h>
 
 /* Define PyVarObject_HEAD_INIT for python 2.5 */
 #ifndef PyVarObject_HEAD_INIT
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 9e25da0..32d8049 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -8,7 +8,7 @@ cflags += getenv('CFLAGS', '').split()
 
 perf = Extension('perf',
 		  sources = ['util/python.c', 'util/ctype.c', 'util/evlist.c',
-			     'util/evsel.c', '../lib/lk/cpumap.c', 'util/thread_map.c',
+			     'util/evsel.c', '../lib/lk/cpumap.c', '../lib/lk/thread_map.c',
 			     '../lib/lk/util.c', 'util/xyarray.c', 'util/cgroup.c'],
 		  include_dirs = ['util/include', '../lib'],
 		  extra_compile_args = cflags,
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 13/18] perf: Export evsel.[ch]
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (11 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 12/18] perf: Export thread_map.[ch] Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 14/18] perf: Export cgroup.[ch] Borislav Petkov
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

This is needed by other tools dealing with perf events. Pull in
xyarray.[ch] with it.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/Makefile                        |    6 +++++-
 tools/lib/lk/Makefile                 |    3 +++
 tools/{perf/util => lib/lk}/xyarray.c |    0
 tools/{perf/util => lib/lk}/xyarray.h |    6 +++---
 tools/lib/{lk => perf}/Makefile       |   24 +++++++-----------------
 tools/{perf/util => lib/perf}/evsel.c |    2 +-
 tools/{perf/util => lib/perf}/evsel.h |   14 +++++++-------
 tools/lib/trace/event-info.c          |    2 +-
 tools/perf/Makefile                   |    8 +-------
 tools/perf/builtin-annotate.c         |    2 +-
 tools/perf/builtin-evlist.c           |    2 +-
 tools/perf/builtin-record.c           |    2 +-
 tools/perf/builtin-report.c           |    2 +-
 tools/perf/builtin-script.c           |    2 +-
 tools/perf/builtin-stat.c             |    2 +-
 tools/perf/builtin-test.c             |    2 +-
 tools/perf/builtin-top.c              |    4 ++--
 tools/perf/util/cgroup.c              |    2 +-
 tools/perf/util/evlist.c              |    2 +-
 tools/perf/util/header.c              |    2 +-
 tools/perf/util/parse-events.c        |    2 +-
 tools/perf/util/python.c              |    2 +-
 tools/perf/util/session.c             |    2 +-
 tools/perf/util/setup.py              |    4 ++--
 tools/perf/util/top.c                 |    2 +-
 tools/perf/util/ui/browsers/hists.c   |    2 +-
 26 files changed, 47 insertions(+), 56 deletions(-)
 rename tools/{perf/util => lib/lk}/xyarray.c (100%)
 rename tools/{perf/util => lib/lk}/xyarray.h (81%)
 copy tools/lib/{lk => perf}/Makefile (69%)
 rename tools/{perf/util => lib/perf}/evsel.c (99%)
 rename tools/{perf/util => lib/perf}/evsel.h (96%)

diff --git a/tools/Makefile b/tools/Makefile
index f302177..60993bf 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -12,7 +12,7 @@ export BASIC_CFLAGS
 PYRF_OBJS =
 export PYRF_OBJS
 
-perf: libtrace liblk .FORCE
+perf: libtrace liblkperf liblk .FORCE
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1)
 
 firewire: .FORCE
@@ -21,6 +21,9 @@ firewire: .FORCE
 liblk: .FORCE
 	$(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1)
 
+liblkperf: .FORCE
+	$(QUIET_SUBDIR0)lib/perf/ $(QUIET_SUBDIR1)
+
 libtrace: .FORCE
 	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1)
 
@@ -43,6 +46,7 @@ clean:
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)firewire/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)lib/perf/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)slub/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)power/x86/turbostat/ $(QUIET_SUBDIR1) clean
diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
index e3c5282..228b033 100644
--- a/tools/lib/lk/Makefile
+++ b/tools/lib/lk/Makefile
@@ -9,16 +9,19 @@ LIB_H += util.h
 LIB_H += types.h
 LIB_H += cpumap.h
 LIB_H += thread_map.h
+LIB_H += xyarray.h
 
 LIB_OBJS += debugfs.o
 LIB_OBJS += usage.o
 LIB_OBJS += util.o
 LIB_OBJS += cpumap.o
 LIB_OBJS += thread_map.o
+LIB_OBJS += xyarray.o
 
 PYRF_OBJS += util.o
 PYRF_OBJS += cpumap.o
 PYRF_OBJS += thread_map.o
+PYRF_OBJS += xyarray.o
 
 LIBFILE = $(LIB_OUTPUT)liblk.a
 
diff --git a/tools/perf/util/xyarray.c b/tools/lib/lk/xyarray.c
similarity index 100%
rename from tools/perf/util/xyarray.c
rename to tools/lib/lk/xyarray.c
diff --git a/tools/perf/util/xyarray.h b/tools/lib/lk/xyarray.h
similarity index 81%
rename from tools/perf/util/xyarray.h
rename to tools/lib/lk/xyarray.h
index c488a07..9029f38 100644
--- a/tools/perf/util/xyarray.h
+++ b/tools/lib/lk/xyarray.h
@@ -1,5 +1,5 @@
-#ifndef _PERF_XYARRAY_H_
-#define _PERF_XYARRAY_H_ 1
+#ifndef __LK_XYARRAY_H_
+#define __LK_XYARRAY_H_ 1
 
 #include <sys/types.h>
 
@@ -17,4 +17,4 @@ static inline void *xyarray__entry(struct xyarray *xy, int x, int y)
 	return &xy->contents[x * xy->row_size + y * xy->entry_size];
 }
 
-#endif /* _PERF_XYARRAY_H_ */
+#endif /* __LK_XYARRAY_H_ */
diff --git a/tools/lib/lk/Makefile b/tools/lib/perf/Makefile
similarity index 69%
copy from tools/lib/lk/Makefile
copy to tools/lib/perf/Makefile
index e3c5282..8b7b288 100644
--- a/tools/lib/lk/Makefile
+++ b/tools/lib/perf/Makefile
@@ -4,23 +4,13 @@ include ../../scripts/Makefile.lib
 LIB_H=
 LIB_OBJS=
 
-LIB_H += debugfs.h
-LIB_H += util.h
-LIB_H += types.h
-LIB_H += cpumap.h
-LIB_H += thread_map.h
-
-LIB_OBJS += debugfs.o
-LIB_OBJS += usage.o
-LIB_OBJS += util.o
-LIB_OBJS += cpumap.o
-LIB_OBJS += thread_map.o
-
-PYRF_OBJS += util.o
-PYRF_OBJS += cpumap.o
-PYRF_OBJS += thread_map.o
-
-LIBFILE = $(LIB_OUTPUT)liblk.a
+LIB_H += evsel.h
+
+LIB_OBJS += evsel.o
+
+PYRF_OBJS += evsel.o
+
+LIBFILE = $(LIB_OUTPUT)liblkperf.a
 
 CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
 EXTLIBS = -lpthread -lrt -lelf -lm
diff --git a/tools/perf/util/evsel.c b/tools/lib/perf/evsel.c
similarity index 99%
rename from tools/perf/util/evsel.c
rename to tools/lib/perf/evsel.c
index 3a63422..a66501c 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -8,7 +8,7 @@
  */
 
 #include "evsel.h"
-#include "evlist.h"
+#include "../../perf/util/evlist.h"
 #include <lk/util.h>
 #include <lk/cpumap.h>
 #include <lk/thread_map.h>
diff --git a/tools/perf/util/evsel.h b/tools/lib/perf/evsel.h
similarity index 96%
rename from tools/perf/util/evsel.h
rename to tools/lib/perf/evsel.h
index 526deed..48e5906 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/lib/perf/evsel.h
@@ -5,10 +5,10 @@
 #include <stdbool.h>
 #include "../../../include/linux/perf_event.h"
 #include <lk/types.h>
-#include "xyarray.h"
-#include "cgroup.h"
-#include "hist.h"
- 
+#include <lk/xyarray.h>
+#include "../../perf/util/cgroup.h"
+#include "../../perf/util/hist.h"
+
 struct perf_counts_values {
 	union {
 		struct {
@@ -21,7 +21,7 @@ struct perf_counts_values {
 };
 
 struct perf_counts {
-	s8		   	  scaled;
+	s8			  scaled;
 	struct perf_counts_values aggr;
 	struct perf_counts_values cpu[];
 };
@@ -33,8 +33,8 @@ struct perf_evsel;
  * more than one entry in the evlist.
  */
 struct perf_sample_id {
-	struct hlist_node 	node;
-	u64		 	id;
+	struct hlist_node	node;
+	u64			id;
 	struct perf_evsel	*evsel;
 };
 
diff --git a/tools/lib/trace/event-info.c b/tools/lib/trace/event-info.c
index dbc6ba9..9da00af 100644
--- a/tools/lib/trace/event-info.c
+++ b/tools/lib/trace/event-info.c
@@ -40,7 +40,7 @@
 #include "../../perf/perf.h"
 #include "trace-event.h"
 #include <lk/debugfs.h>
-#include "../perf/util/evsel.h"
+#include <perf/evsel.h>
 
 #define VERSION "0.5"
 
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 05c4eef..af2bd00 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -175,7 +175,7 @@ export PERL_PATH
 
 LIB_FILE=$(OUTPUT)libperf.a
 
-EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a $(LIB_OUTPUT)liblk.a
+EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a $(LIB_OUTPUT)liblk.a $(LIB_OUTPUT)liblkperf.a
 
 LIB_H += ../../include/linux/perf_event.h
 LIB_H += ../../include/linux/rbtree.h
@@ -212,7 +212,6 @@ LIB_H += util/callchain.h
 LIB_H += util/build-id.h
 LIB_H += util/debug.h
 LIB_H += util/event.h
-LIB_H += util/evsel.h
 LIB_H += util/evlist.h
 LIB_H += util/exec_cmd.h
 LIB_H += util/levenshtein.h
@@ -220,7 +219,6 @@ LIB_H += util/map.h
 LIB_H += util/parse-options.h
 LIB_H += util/parse-events.h
 LIB_H += util/quote.h
-LIB_H += util/xyarray.h
 LIB_H += util/header.h
 LIB_H += util/help.h
 LIB_H += util/session.h
@@ -252,7 +250,6 @@ LIB_OBJS += $(OUTPUT)util/ctype.o
 LIB_OBJS += $(OUTPUT)util/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
 LIB_OBJS += $(OUTPUT)util/evlist.o
-LIB_OBJS += $(OUTPUT)util/evsel.o
 LIB_OBJS += $(OUTPUT)util/exec_cmd.o
 LIB_OBJS += $(OUTPUT)util/help.o
 LIB_OBJS += $(OUTPUT)util/levenshtein.o
@@ -287,7 +284,6 @@ LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
 LIB_OBJS += $(OUTPUT)util/hist.o
 LIB_OBJS += $(OUTPUT)util/probe-event.o
-LIB_OBJS += $(OUTPUT)util/xyarray.o
 LIB_OBJS += $(OUTPUT)util/cgroup.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
@@ -331,9 +327,7 @@ PERFLIBS = $(LIB_FILE) $(EXTRA_LIBS)
 
 PYRF_OBJS += $(OUTPUT)util/ctype.o
 PYRF_OBJS += $(OUTPUT)util/evlist.o
-PYRF_OBJS += $(OUTPUT)util/evsel.o
 PYRF_OBJS += $(OUTPUT)util/python.o
-PYRF_OBJS += $(OUTPUT)util/xyarray.o
 
 #
 # Platform specific tweaks
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 2003f27..6386254 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -20,7 +20,7 @@
 #include "util/debug.h"
 
 #include "util/evlist.h"
-#include "util/evsel.h"
+#include <perf/evsel.h>
 #include "util/annotate.h"
 #include "util/event.h"
 #include "util/parse-options.h"
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index 356573c..3619582 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -9,7 +9,7 @@
 
 #include "perf.h"
 #include "util/evlist.h"
-#include "util/evsel.h"
+#include <perf/evsel.h>
 #include "util/parse-events.h"
 #include "util/parse-options.h"
 #include "util/session.h"
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 7011ef3..77ffcc5 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -19,7 +19,7 @@
 #include "util/header.h"
 #include "util/event.h"
 #include "util/evlist.h"
-#include "util/evsel.h"
+#include <perf/evsel.h>
 #include "util/debug.h"
 #include "util/session.h"
 #include "util/symbol.h"
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 876d3e2..0700778 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -22,7 +22,7 @@
 #include "perf.h"
 #include "util/debug.h"
 #include "util/evlist.h"
-#include "util/evsel.h"
+#include <perf/evsel.h>
 #include "util/header.h"
 #include "util/session.h"
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 8ff8e1b..65583d8 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -13,7 +13,7 @@
 #include "util/parse-options.h"
 #include <lk/util.h>
 #include "util/evlist.h"
-#include "util/evsel.h"
+#include <perf/evsel.h>
 
 static char const		*script_name;
 static char const		*generate_script_lang;
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index e2d57dd..58374af 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -44,7 +44,7 @@
 #include "util/parse-events.h"
 #include "util/event.h"
 #include "util/evlist.h"
-#include "util/evsel.h"
+#include <perf/evsel.h>
 #include "util/debug.h"
 #include "util/header.h"
 #include <lk/cpumap.h>
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index e471fe9..12feeb4 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -236,7 +236,7 @@ out:
 }
 
 #include <lk/cpumap.h>
-#include "util/evsel.h"
+#include <perf/evsel.h>
 #include <sys/types.h>
 
 static int trace_event__id(const char *evname)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 2cd2e8c..0d778aa 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -24,7 +24,7 @@
 #include "util/cache.h"
 #include "util/color.h"
 #include "util/evlist.h"
-#include "util/evsel.h"
+#include <perf/evsel.h>
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/thread.h"
@@ -35,7 +35,7 @@
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 #include <lk/cpumap.h>
-#include "util/xyarray.h"
+#include <lk/xyarray.h>
 
 #include "util/debug.h"
 
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 99267b3..eae7d6b 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -1,7 +1,7 @@
 #include <lk/util.h>
 #include "../perf.h"
 #include "parse-options.h"
-#include "evsel.h"
+#include <perf/evsel.h>
 #include "cgroup.h"
 #include <lk/debugfs.h> /* MAX_PATH, STR() */
 #include "evlist.h"
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 1f35fec..eb728d0 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -10,7 +10,7 @@
 #include <lk/cpumap.h>
 #include <lk/thread_map.h>
 #include "evlist.h"
-#include "evsel.h"
+#include <perf/evsel.h>
 #include "debug.h"
 #include <lk/util.h>
 
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 4c89af6..8fc4d21 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -9,7 +9,7 @@
 #include <linux/kernel.h>
 
 #include "evlist.h"
-#include "evsel.h"
+#include <perf/evsel.h>
 #include <lk/util.h>
 #include "header.h"
 #include "../perf.h"
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 18f2d1c..9acaab1 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -2,7 +2,7 @@
 #include <lk/util.h>
 #include "../perf.h"
 #include "evlist.h"
-#include "evsel.h"
+#include <perf/evsel.h>
 #include "parse-options.h"
 #include "parse-events.h"
 #include "exec_cmd.h"
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 756f50c..c049b9a 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -3,7 +3,7 @@
 #include <inttypes.h>
 #include <poll.h>
 #include "evlist.h"
-#include "evsel.h"
+#include <perf/evsel.h>
 #include "event.h"
 #include <lk/cpumap.h>
 #include <lk/thread_map.h>
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 46c80de..445a6b9 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 
 #include "evlist.h"
-#include "evsel.h"
+#include <perf/evsel.h>
 #include "session.h"
 #include "sort.h"
 #include <lk/util.h>
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 32d8049..c8d0d8d 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -8,8 +8,8 @@ cflags += getenv('CFLAGS', '').split()
 
 perf = Extension('perf',
 		  sources = ['util/python.c', 'util/ctype.c', 'util/evlist.c',
-			     'util/evsel.c', '../lib/lk/cpumap.c', '../lib/lk/thread_map.c',
-			     '../lib/lk/util.c', 'util/xyarray.c', 'util/cgroup.c'],
+			     '../lib/perf/evsel.c', '../lib/lk/cpumap.c', '../lib/lk/thread_map.c',
+			     '../lib/lk/util.c', '../lib/lk/xyarray.c', 'util/cgroup.c'],
 		  include_dirs = ['util/include', '../lib'],
 		  extra_compile_args = cflags,
                  )
diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c
index 0b027aa..7fb9658 100644
--- a/tools/perf/util/top.c
+++ b/tools/perf/util/top.c
@@ -9,7 +9,7 @@
 #include <lk/cpumap.h>
 #include "event.h"
 #include "evlist.h"
-#include "evsel.h"
+#include <perf/evsel.h>
 #include "parse-events.h"
 #include "symbol.h"
 #include "top.h"
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c
index 453aad2..c4f424b 100644
--- a/tools/perf/util/ui/browsers/hists.c
+++ b/tools/perf/util/ui/browsers/hists.c
@@ -7,7 +7,7 @@
 #include <newt.h>
 #include <linux/rbtree.h>
 
-#include "../../evsel.h"
+#include <perf/evsel.h>
 #include "../../evlist.h"
 #include "../../hist.h"
 #include "../../pstack.h"
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 14/18] perf: Export cgroup.[ch]
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (12 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 13/18] perf: Export evsel.[ch] Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 15/18] perf: Export evlist.[ch] Borislav Petkov
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

This is pulled in by the previous evsel.[ch] export.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/lib/perf/Makefile                |    2 ++
 tools/{perf/util => lib/perf}/cgroup.c |    6 +++---
 tools/{perf/util => lib/perf}/cgroup.h |    6 +++---
 tools/lib/perf/evsel.h                 |    2 +-
 tools/perf/Makefile                    |    2 --
 5 files changed, 9 insertions(+), 9 deletions(-)
 rename tools/{perf/util => lib/perf}/cgroup.c (96%)
 rename tools/{perf/util => lib/perf}/cgroup.h (76%)

diff --git a/tools/lib/perf/Makefile b/tools/lib/perf/Makefile
index 8b7b288..e43008d 100644
--- a/tools/lib/perf/Makefile
+++ b/tools/lib/perf/Makefile
@@ -5,8 +5,10 @@ LIB_H=
 LIB_OBJS=
 
 LIB_H += evsel.h
+LIB_H += cgroup.h
 
 LIB_OBJS += evsel.o
+LIB_OBJS += cgroup.o
 
 PYRF_OBJS += evsel.o
 
diff --git a/tools/perf/util/cgroup.c b/tools/lib/perf/cgroup.c
similarity index 96%
rename from tools/perf/util/cgroup.c
rename to tools/lib/perf/cgroup.c
index eae7d6b..5c9c554 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/lib/perf/cgroup.c
@@ -1,10 +1,10 @@
 #include <lk/util.h>
-#include "../perf.h"
-#include "parse-options.h"
+#include "../../perf/perf.h"
+#include "../../perf/util/parse-options.h"
 #include <perf/evsel.h>
 #include "cgroup.h"
 #include <lk/debugfs.h> /* MAX_PATH, STR() */
-#include "evlist.h"
+#include "../../perf/util/evlist.h"
 
 int nr_cgroups;
 
diff --git a/tools/perf/util/cgroup.h b/tools/lib/perf/cgroup.h
similarity index 76%
rename from tools/perf/util/cgroup.h
rename to tools/lib/perf/cgroup.h
index 89acd6d..a17f2b5 100644
--- a/tools/perf/util/cgroup.h
+++ b/tools/lib/perf/cgroup.h
@@ -1,5 +1,5 @@
-#ifndef __CGROUP_H__
-#define __CGROUP_H__
+#ifndef __PERF_CGROUP_H__
+#define __PERF_CGROUP_H__
 
 struct option;
 
@@ -14,4 +14,4 @@ extern int nr_cgroups; /* number of explicit cgroups defined */
 extern void close_cgroup(struct cgroup_sel *cgrp);
 extern int parse_cgroups(const struct option *opt, const char *str, int unset);
 
-#endif /* __CGROUP_H__ */
+#endif /* __PERF_CGROUP_H__ */
diff --git a/tools/lib/perf/evsel.h b/tools/lib/perf/evsel.h
index 48e5906..ec5f121 100644
--- a/tools/lib/perf/evsel.h
+++ b/tools/lib/perf/evsel.h
@@ -6,7 +6,7 @@
 #include "../../../include/linux/perf_event.h"
 #include <lk/types.h>
 #include <lk/xyarray.h>
-#include "../../perf/util/cgroup.h"
+#include "cgroup.h"
 #include "../../perf/util/hist.h"
 
 struct perf_counts_values {
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index af2bd00..d134897 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -239,7 +239,6 @@ LIB_H += util/probe-event.h
 LIB_H += util/pstack.h
 LIB_H += util/top.h
 LIB_H += $(ARCH_INCLUDE)
-LIB_H += util/cgroup.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -284,7 +283,6 @@ LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
 LIB_OBJS += $(OUTPUT)util/hist.o
 LIB_OBJS += $(OUTPUT)util/probe-event.o
-LIB_OBJS += $(OUTPUT)util/cgroup.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 15/18] perf: Export evlist.[ch]
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (13 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 14/18] perf: Export cgroup.[ch] Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 16/18] perf: Export ctype.c Borislav Petkov
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Export for other tools to use too. Also, add a weak ui_warning version
when using evlist outside of perf.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/lib/perf/Makefile                  |    3 +++
 tools/lib/perf/cgroup.c                  |    6 +++---
 tools/{perf/util => lib/perf}/evlist.c   |   11 ++++++++++-
 tools/{perf/util => lib/perf}/evlist.h   |    4 ++--
 tools/lib/perf/evsel.c                   |    2 +-
 tools/perf/Makefile                      |    3 ---
 tools/perf/builtin-annotate.c            |    2 +-
 tools/perf/builtin-evlist.c              |    2 +-
 tools/perf/builtin-record.c              |    2 +-
 tools/perf/builtin-report.c              |    2 +-
 tools/perf/builtin-script.c              |    2 +-
 tools/perf/builtin-stat.c                |    2 +-
 tools/perf/builtin-test.c                |    2 +-
 tools/perf/builtin-top.c                 |    2 +-
 tools/perf/util/header.c                 |    2 +-
 tools/perf/util/include/linux/compiler.h |    1 +
 tools/perf/util/parse-events.c           |    2 +-
 tools/perf/util/python.c                 |    2 +-
 tools/perf/util/session.c                |    2 +-
 tools/perf/util/setup.py                 |    2 +-
 tools/perf/util/top.c                    |    2 +-
 tools/perf/util/ui/browsers/hists.c      |    2 +-
 tools/perf/util/ui/browsers/top.c        |    2 +-
 23 files changed, 36 insertions(+), 26 deletions(-)
 rename tools/{perf/util => lib/perf}/evlist.c (98%)
 rename tools/{perf/util => lib/perf}/evlist.h (96%)

diff --git a/tools/lib/perf/Makefile b/tools/lib/perf/Makefile
index e43008d..1e5c857 100644
--- a/tools/lib/perf/Makefile
+++ b/tools/lib/perf/Makefile
@@ -6,11 +6,14 @@ LIB_OBJS=
 
 LIB_H += evsel.h
 LIB_H += cgroup.h
+LIB_H += evlist.h
 
 LIB_OBJS += evsel.o
 LIB_OBJS += cgroup.o
+LIB_OBJS += evlist.o
 
 PYRF_OBJS += evsel.o
+PYRF_OBJS += evlist.o
 
 LIBFILE = $(LIB_OUTPUT)liblkperf.a
 
diff --git a/tools/lib/perf/cgroup.c b/tools/lib/perf/cgroup.c
index 5c9c554..8181353 100644
--- a/tools/lib/perf/cgroup.c
+++ b/tools/lib/perf/cgroup.c
@@ -1,10 +1,10 @@
 #include <lk/util.h>
+#include <lk/debugfs.h> /* MAX_PATH, STR() */
 #include "../../perf/perf.h"
 #include "../../perf/util/parse-options.h"
-#include <perf/evsel.h>
+#include "evsel.h"
 #include "cgroup.h"
-#include <lk/debugfs.h> /* MAX_PATH, STR() */
-#include "../../perf/util/evlist.h"
+#include "evlist.h"
 
 int nr_cgroups;
 
diff --git a/tools/perf/util/evlist.c b/tools/lib/perf/evlist.c
similarity index 98%
rename from tools/perf/util/evlist.c
rename to tools/lib/perf/evlist.c
index eb728d0..ccbcf04 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/lib/perf/evlist.c
@@ -11,7 +11,7 @@
 #include <lk/thread_map.h>
 #include "evlist.h"
 #include <perf/evsel.h>
-#include "debug.h"
+#include "../../perf/util/debug.h"
 #include <lk/util.h>
 
 #include <sys/mman.h>
@@ -248,6 +248,15 @@ int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
 	return evlist->mmap != NULL ? 0 : -ENOMEM;
 }
 
+void __weak ui__warning(const char *format, ...)
+{
+	va_list params;
+
+	va_start(params, format);
+	warning(format, params);
+	va_end(params);
+}
+
 static int __perf_evlist__mmap(struct perf_evlist *evlist, struct perf_evsel *evsel,
 			       int cpu, int prot, int mask, int fd)
 {
diff --git a/tools/perf/util/evlist.h b/tools/lib/perf/evlist.h
similarity index 96%
rename from tools/perf/util/evlist.h
rename to tools/lib/perf/evlist.h
index 8b1cb7a..9480b1d 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/lib/perf/evlist.h
@@ -2,8 +2,8 @@
 #define __PERF_EVLIST_H 1
 
 #include <linux/list.h>
-#include "../perf.h"
-#include "event.h"
+#include "../../perf/perf.h"
+#include "../../perf/util/event.h"
 
 struct pollfd;
 struct thread_map;
diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
index a66501c..3a63422 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -8,7 +8,7 @@
  */
 
 #include "evsel.h"
-#include "../../perf/util/evlist.h"
+#include "evlist.h"
 #include <lk/util.h>
 #include <lk/cpumap.h>
 #include <lk/thread_map.h>
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index d134897..2edfa70 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -212,7 +212,6 @@ LIB_H += util/callchain.h
 LIB_H += util/build-id.h
 LIB_H += util/debug.h
 LIB_H += util/event.h
-LIB_H += util/evlist.h
 LIB_H += util/exec_cmd.h
 LIB_H += util/levenshtein.h
 LIB_H += util/map.h
@@ -248,7 +247,6 @@ LIB_OBJS += $(OUTPUT)util/config.o
 LIB_OBJS += $(OUTPUT)util/ctype.o
 LIB_OBJS += $(OUTPUT)util/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
-LIB_OBJS += $(OUTPUT)util/evlist.o
 LIB_OBJS += $(OUTPUT)util/exec_cmd.o
 LIB_OBJS += $(OUTPUT)util/help.o
 LIB_OBJS += $(OUTPUT)util/levenshtein.o
@@ -324,7 +322,6 @@ PERFLIBS = $(LIB_FILE) $(EXTRA_LIBS)
 # tools/perf/util/setup.py
 
 PYRF_OBJS += $(OUTPUT)util/ctype.o
-PYRF_OBJS += $(OUTPUT)util/evlist.o
 PYRF_OBJS += $(OUTPUT)util/python.o
 
 #
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 6386254..da5bd09 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -19,7 +19,7 @@
 #include "perf.h"
 #include "util/debug.h"
 
-#include "util/evlist.h"
+#include <perf/evlist.h>
 #include <perf/evsel.h>
 #include "util/annotate.h"
 #include "util/event.h"
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index 3619582..0f869cc 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -8,7 +8,7 @@
 #include <linux/list.h>
 
 #include "perf.h"
-#include "util/evlist.h"
+#include <perf/evlist.h>
 #include <perf/evsel.h>
 #include "util/parse-events.h"
 #include "util/parse-options.h"
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 77ffcc5..5f1b66a 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -18,7 +18,7 @@
 
 #include "util/header.h"
 #include "util/event.h"
-#include "util/evlist.h"
+#include <perf/evlist.h>
 #include <perf/evsel.h>
 #include "util/debug.h"
 #include "util/session.h"
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 0700778..07568f4 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -21,7 +21,7 @@
 
 #include "perf.h"
 #include "util/debug.h"
-#include "util/evlist.h"
+#include <perf/evlist.h>
 #include <perf/evsel.h>
 #include "util/header.h"
 #include "util/session.h"
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 65583d8..9c95a72 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -12,7 +12,7 @@
 #include <trace/trace-event.h>
 #include "util/parse-options.h"
 #include <lk/util.h>
-#include "util/evlist.h"
+#include <perf/evlist.h>
 #include <perf/evsel.h>
 
 static char const		*script_name;
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 58374af..b56dc56 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -43,7 +43,7 @@
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 #include "util/event.h"
-#include "util/evlist.h"
+#include <perf/evlist.h>
 #include <perf/evsel.h>
 #include "util/debug.h"
 #include "util/header.h"
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 12feeb4..f045eb0 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -7,7 +7,7 @@
 
 #include "util/cache.h"
 #include "util/debug.h"
-#include "util/evlist.h"
+#include <perf/evlist.h>
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 #include "util/symbol.h"
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 0d778aa..16d94be 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -23,7 +23,7 @@
 #include "util/annotate.h"
 #include "util/cache.h"
 #include "util/color.h"
-#include "util/evlist.h"
+#include <perf/evlist.h>
 #include <perf/evsel.h>
 #include "util/session.h"
 #include "util/symbol.h"
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 8fc4d21..1948c88 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -8,7 +8,7 @@
 #include <linux/list.h>
 #include <linux/kernel.h>
 
-#include "evlist.h"
+#include <perf/evlist.h>
 #include <perf/evsel.h>
 #include <lk/util.h>
 #include "header.h"
diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h
index 791f9dd..62165bc 100644
--- a/tools/perf/util/include/linux/compiler.h
+++ b/tools/perf/util/include/linux/compiler.h
@@ -8,5 +8,6 @@
 #define __attribute_const__
 
 #define __used		__attribute__((__unused__))
+#define __weak		__attribute__((weak))
 
 #endif
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 9acaab1..05e8e65 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1,7 +1,7 @@
 #include "../../../include/linux/hw_breakpoint.h"
 #include <lk/util.h>
 #include "../perf.h"
-#include "evlist.h"
+#include <perf/evlist.h>
 #include <perf/evsel.h>
 #include "parse-options.h"
 #include "parse-events.h"
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index c049b9a..4f2745e 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -2,7 +2,7 @@
 #include <structmember.h>
 #include <inttypes.h>
 #include <poll.h>
-#include "evlist.h"
+#include <perf/evlist.h>
 #include <perf/evsel.h>
 #include "event.h"
 #include <lk/cpumap.h>
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 445a6b9..a81bb60 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -7,7 +7,7 @@
 #include <sys/types.h>
 #include <sys/mman.h>
 
-#include "evlist.h"
+#include <perf/evlist.h>
 #include <perf/evsel.h>
 #include "session.h"
 #include "sort.h"
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index c8d0d8d..7172967 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -7,7 +7,7 @@ cflags = ['-fno-strict-aliasing', '-Wno-write-strings']
 cflags += getenv('CFLAGS', '').split()
 
 perf = Extension('perf',
-		  sources = ['util/python.c', 'util/ctype.c', 'util/evlist.c',
+		  sources = ['util/python.c', 'util/ctype.c', '../lib/perf/evlist.c',
 			     '../lib/perf/evsel.c', '../lib/lk/cpumap.c', '../lib/lk/thread_map.c',
 			     '../lib/lk/util.c', '../lib/lk/xyarray.c', 'util/cgroup.c'],
 		  include_dirs = ['util/include', '../lib'],
diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c
index 7fb9658..5d939b6 100644
--- a/tools/perf/util/top.c
+++ b/tools/perf/util/top.c
@@ -8,7 +8,7 @@
 
 #include <lk/cpumap.h>
 #include "event.h"
-#include "evlist.h"
+#include <perf/evlist.h>
 #include <perf/evsel.h>
 #include "parse-events.h"
 #include "symbol.h"
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c
index c4f424b..d9dae5d 100644
--- a/tools/perf/util/ui/browsers/hists.c
+++ b/tools/perf/util/ui/browsers/hists.c
@@ -8,7 +8,7 @@
 #include <linux/rbtree.h>
 
 #include <perf/evsel.h>
-#include "../../evlist.h"
+#include <perf/evlist.h>
 #include "../../hist.h"
 #include "../../pstack.h"
 #include "../../sort.h"
diff --git a/tools/perf/util/ui/browsers/top.c b/tools/perf/util/ui/browsers/top.c
index 5a06538..ba59d3d 100644
--- a/tools/perf/util/ui/browsers/top.c
+++ b/tools/perf/util/ui/browsers/top.c
@@ -11,7 +11,7 @@
 #include "../helpline.h"
 #include "../libslang.h"
 #include "../util.h"
-#include "../../evlist.h"
+#include <perf/evlist.h>
 #include "../../hist.h"
 #include "../../sort.h"
 #include "../../symbol.h"
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 16/18] perf: Export ctype.c
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (14 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 15/18] perf: Export evlist.[ch] Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 17/18] perf: Export tracepoint_id_to_path Borislav Petkov
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

This is needed when linking against libtrace.a

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/lib/lk/Makefile               |    1 +
 tools/{perf/util => lib/lk}/ctype.c |    2 +-
 tools/perf/Makefile                 |    1 -
 3 files changed, 2 insertions(+), 2 deletions(-)
 rename tools/{perf/util => lib/lk}/ctype.c (98%)

diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
index 228b033..d444c5b 100644
--- a/tools/lib/lk/Makefile
+++ b/tools/lib/lk/Makefile
@@ -11,6 +11,7 @@ LIB_H += cpumap.h
 LIB_H += thread_map.h
 LIB_H += xyarray.h
 
+LIB_OBJS += ctype.o
 LIB_OBJS += debugfs.o
 LIB_OBJS += usage.o
 LIB_OBJS += util.o
diff --git a/tools/perf/util/ctype.c b/tools/lib/lk/ctype.c
similarity index 98%
rename from tools/perf/util/ctype.c
rename to tools/lib/lk/ctype.c
index 3507362..aada3ac 100644
--- a/tools/perf/util/ctype.c
+++ b/tools/lib/lk/ctype.c
@@ -3,7 +3,7 @@
  *
  * No surprises, and works with signed and unsigned chars.
  */
-#include "cache.h"
+#include "util.h"
 
 enum {
 	S = GIT_SPACE,
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 2edfa70..eb7f370 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -244,7 +244,6 @@ LIB_OBJS += $(OUTPUT)util/alias.o
 LIB_OBJS += $(OUTPUT)util/annotate.o
 LIB_OBJS += $(OUTPUT)util/build-id.o
 LIB_OBJS += $(OUTPUT)util/config.o
-LIB_OBJS += $(OUTPUT)util/ctype.o
 LIB_OBJS += $(OUTPUT)util/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
 LIB_OBJS += $(OUTPUT)util/exec_cmd.o
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 17/18] perf: Export tracepoint_id_to_path
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (15 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 16/18] perf: Export ctype.c Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-23 16:28 ` [PATCH 18/18] ras: Add RAS daemon Borislav Petkov
  2011-04-29 14:08 ` [PATCH 00/18] RAS daemon: Easter Eggs Edition Frederic Weisbecker
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

This is needed when linking against libtrace.a so move it to
<lib/trace/trace-event-info.c> and adjust all headers accordingly.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/lib/trace/event-info.c    |  120 +++++++++++++++++++++++++++++++++------
 tools/lib/trace/trace-event.h   |   19 ++++++
 tools/perf/util/parse-events.c  |  104 +--------------------------------
 tools/perf/util/parse-events.h  |    1 -
 tools/perf/util/parse-options.h |    1 +
 5 files changed, 126 insertions(+), 119 deletions(-)

diff --git a/tools/lib/trace/event-info.c b/tools/lib/trace/event-info.c
index 9da00af..fb71c34 100644
--- a/tools/lib/trace/event-info.c
+++ b/tools/lib/trace/event-info.c
@@ -18,7 +18,6 @@
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  */
-#define _GNU_SOURCE
 #include <dirent.h>
 #include <mntent.h>
 #include <stdio.h>
@@ -26,6 +25,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <sys/types.h>
+#include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <pthread.h>
@@ -40,6 +40,7 @@
 #include "../../perf/perf.h"
 #include "trace-event.h"
 #include <lk/debugfs.h>
+#include <lk/util.h>
 #include <perf/evsel.h>
 
 #define VERSION "0.5"
@@ -58,6 +59,7 @@
 unsigned int page_size;
 
 static const char *output_file = "trace.info";
+static const char *dfs_path;
 static int output_fd;
 
 struct event_list {
@@ -72,7 +74,7 @@ struct events {
 	char *name;
 };
 
-static void die(const char *fmt, ...)
+static void t_die(const char *fmt, ...)
 {
 	va_list ap;
 	int ret = errno;
@@ -97,7 +99,7 @@ void *malloc_or_die(unsigned int size)
 
 	data = malloc(size);
 	if (!data)
-		die("malloc");
+		t_die("malloc");
 	return data;
 }
 
@@ -106,7 +108,7 @@ static const char *find_debugfs(void)
 	const char *path = debugfs_mount(NULL);
 
 	if (!path)
-		die("Your kernel not support debugfs filesystem");
+		t_die("Your kernel not support debugfs filesystem");
 
 	return path;
 }
@@ -167,7 +169,7 @@ static ssize_t write_or_die(const void *buf, size_t len)
 
 	ret = write(output_fd, buf, len);
 	if (ret < 0)
-		die("writing to '%s'", output_file);
+		t_die("writing to '%s'", output_file);
 
 	return ret;
 }
@@ -205,7 +207,7 @@ static unsigned long long copy_file(const char *file)
 
 	fd = open(file, O_RDONLY);
 	if (fd < 0)
-		die("Can't read '%s'", file);
+		t_die("Can't read '%s'", file);
 	size = copy_file_fd(fd);
 	close(fd);
 
@@ -236,7 +238,7 @@ unsigned long get_filesize(const char *file)
 
 	fd = open(file, O_RDONLY);
 	if (fd < 0)
-		die("Can't read '%s'", file);
+		t_die("Can't read '%s'", file);
 	size = get_size_fd(fd);
 	close(fd);
 
@@ -252,7 +254,7 @@ static void read_header_files(void)
 	path = get_tracing_file("events/header_page");
 	fd = open(path, O_RDONLY);
 	if (fd < 0)
-		die("can't read '%s'", path);
+		t_die("can't read '%s'", path);
 
 	/* unfortunately, you can not stat debugfs files for size */
 	size = get_size_fd(fd);
@@ -263,14 +265,14 @@ static void read_header_files(void)
 	close(fd);
 
 	if (size != check_size)
-		die("wrong size for '%s' size=%lld read=%lld",
+		t_die("wrong size for '%s' size=%lld read=%lld",
 		    path, size, check_size);
 	put_tracing_file(path);
 
 	path = get_tracing_file("events/header_event");
 	fd = open(path, O_RDONLY);
 	if (fd < 0)
-		die("can't read '%s'", path);
+		t_die("can't read '%s'", path);
 
 	size = get_size_fd(fd);
 
@@ -278,7 +280,7 @@ static void read_header_files(void)
 	write_or_die(&size, 8);
 	check_size = copy_file_fd(fd);
 	if (size != check_size)
-		die("wrong size for '%s'", path);
+		t_die("wrong size for '%s'", path);
 	put_tracing_file(path);
 	close(fd);
 }
@@ -306,7 +308,7 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps)
 
 	dir = opendir(sys);
 	if (!dir)
-		die("can't read directory '%s'", sys);
+		t_die("can't read directory '%s'", sys);
 
 	while ((dent = readdir(dir))) {
 		if (dent->d_type != DT_DIR ||
@@ -342,7 +344,7 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps)
 			write_or_die(&size, 8);
 			check_size = copy_file(format);
 			if (size != check_size)
-				die("error in size of file '%s'", format);
+				t_die("error in size of file '%s'", format);
 		}
 
 		free(format);
@@ -386,7 +388,7 @@ static void read_event_files(struct tracepoint_path *tps)
 
 	dir = opendir(path);
 	if (!dir)
-		die("can't read directory '%s'", path);
+		t_die("can't read directory '%s'", path);
 
 	while ((dent = readdir(dir))) {
 		if (dent->d_type != DT_DIR ||
@@ -440,7 +442,7 @@ static void read_proc_kallsyms(void)
 	write_or_die(&size, 4);
 	check_size = copy_file(path);
 	if (size != check_size)
-		die("error in size of file '%s'", path);
+		t_die("error in size of file '%s'", path);
 
 }
 
@@ -463,11 +465,95 @@ static void read_ftrace_printk(void)
 	write_or_die(&size, 4);
 	check_size = copy_file(path);
 	if (size != check_size)
-		die("error in size of file '%s'", path);
+		t_die("error in size of file '%s'", path);
 out:
 	put_tracing_file(path);
 }
 
+int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
+{
+	char evt_path[MAXPATHLEN];
+	int fd;
+
+	snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", dfs_path,
+			sys_dir->d_name, evt_dir->d_name);
+	fd = open(evt_path, O_RDONLY);
+	if (fd < 0)
+		return -EINVAL;
+	close(fd);
+
+	return 0;
+}
+
+struct tracepoint_path *tracepoint_id_to_path(u64 config)
+{
+	struct tracepoint_path *path = NULL;
+	DIR *sys_dir, *evt_dir;
+	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
+	char id_buf[4];
+	int fd;
+	u64 id;
+	char evt_path[MAXPATHLEN];
+	char dir_path[MAXPATHLEN];
+
+	dfs_path = debugfs_mount(NULL);
+	if (!dfs_path)
+		return NULL;
+
+	sys_dir = opendir(dfs_path);
+	if (!sys_dir)
+		return NULL;
+
+	for_each_subsystem(sys_dir, sys_dirent, sys_next) {
+
+		snprintf(dir_path, MAXPATHLEN, "%s/%s", dfs_path,
+			 sys_dirent.d_name);
+		evt_dir = opendir(dir_path);
+		if (!evt_dir)
+			continue;
+
+		for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
+
+			snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
+				 evt_dirent.d_name);
+			fd = open(evt_path, O_RDONLY);
+			if (fd < 0)
+				continue;
+			if (read(fd, id_buf, sizeof(id_buf)) < 0) {
+				close(fd);
+				continue;
+			}
+			close(fd);
+			id = atoll(id_buf);
+			if (id == config) {
+				closedir(evt_dir);
+				closedir(sys_dir);
+				path = zalloc(sizeof(*path));
+				path->system = malloc(MAX_EVENT_LENGTH);
+				if (!path->system) {
+					free(path);
+					return NULL;
+				}
+				path->name = malloc(MAX_EVENT_LENGTH);
+				if (!path->name) {
+					free(path->system);
+					free(path);
+					return NULL;
+				}
+				strncpy(path->system, sys_dirent.d_name,
+					MAX_EVENT_LENGTH);
+				strncpy(path->name, evt_dirent.d_name,
+					MAX_EVENT_LENGTH);
+				return path;
+			}
+		}
+		closedir(evt_dir);
+	}
+
+	closedir(sys_dir);
+	return NULL;
+}
+
 static struct tracepoint_path *
 get_tracepoints_path(struct list_head *pattrs)
 {
@@ -481,7 +567,7 @@ get_tracepoints_path(struct list_head *pattrs)
 		++nr_tracepoints;
 		ppath->next = tracepoint_id_to_path(pos->attr.config);
 		if (!ppath->next)
-			die("%s\n", "No memory to alloc tracepoints list");
+			t_die("%s\n", "No memory to alloc tracepoints list");
 		ppath = ppath->next;
 	}
 
diff --git a/tools/lib/trace/trace-event.h b/tools/lib/trace/trace-event.h
index 8510207..1477eca 100644
--- a/tools/lib/trace/trace-event.h
+++ b/tools/lib/trace/trace-event.h
@@ -2,6 +2,7 @@
 #define __LIB_TRACE_EVENTS_H
 
 #include <stdbool.h>
+#include <dirent.h>
 #include <linux/compiler.h>
 
 #include "../../perf/util/session.h"
@@ -317,4 +318,22 @@ int common_pc(struct scripting_context *context);
 int common_flags(struct scripting_context *context);
 int common_lock_depth(struct scripting_context *context);
 
+#define MAX_EVENT_LENGTH 512
+#define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1)
+
+#define for_each_subsystem(sys_dir, sys_dirent, sys_next)	       \
+	while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next)	       \
+	if (sys_dirent.d_type == DT_DIR &&				       \
+	   (strcmp(sys_dirent.d_name, ".")) &&				       \
+	   (strcmp(sys_dirent.d_name, "..")))
+
+#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next)	       \
+	while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next)        \
+	if (evt_dirent.d_type == DT_DIR &&				       \
+	   (strcmp(evt_dirent.d_name, ".")) &&				       \
+	   (strcmp(evt_dirent.d_name, "..")) &&				       \
+	   (!tp_event_has_id(&sys_dirent, &evt_dirent)))
+
+extern int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir);
+extern struct tracepoint_path *tracepoint_id_to_path(u64 config);
 #endif /* __LIB_TRACE_EVENTS_H */
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 05e8e65..c76008f 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1,5 +1,4 @@
 #include "../../../include/linux/hw_breakpoint.h"
-#include <lk/util.h>
 #include "../perf.h"
 #include <perf/evlist.h>
 #include <perf/evsel.h>
@@ -10,7 +9,10 @@
 #include "symbol.h"
 #include "cache.h"
 #include "header.h"
+
 #include <lk/debugfs.h>
+#include <lk/util.h>
+#include <trace/trace-event.h>
 
 struct event_symbol {
 	u8		type;
@@ -122,106 +124,6 @@ static unsigned long hw_cache_stat[C(MAX)] = {
  [C(BPU)]	= (CACHE_READ),
 };
 
-#define for_each_subsystem(sys_dir, sys_dirent, sys_next)	       \
-	while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next)	       \
-	if (sys_dirent.d_type == DT_DIR &&				       \
-	   (strcmp(sys_dirent.d_name, ".")) &&				       \
-	   (strcmp(sys_dirent.d_name, "..")))
-
-static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
-{
-	char evt_path[MAXPATHLEN];
-	int fd;
-
-	snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
-			sys_dir->d_name, evt_dir->d_name);
-	fd = open(evt_path, O_RDONLY);
-	if (fd < 0)
-		return -EINVAL;
-	close(fd);
-
-	return 0;
-}
-
-#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next)	       \
-	while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next)        \
-	if (evt_dirent.d_type == DT_DIR &&				       \
-	   (strcmp(evt_dirent.d_name, ".")) &&				       \
-	   (strcmp(evt_dirent.d_name, "..")) &&				       \
-	   (!tp_event_has_id(&sys_dirent, &evt_dirent)))
-
-#define MAX_EVENT_LENGTH 512
-
-
-struct tracepoint_path *tracepoint_id_to_path(u64 config)
-{
-	struct tracepoint_path *path = NULL;
-	DIR *sys_dir, *evt_dir;
-	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
-	char id_buf[4];
-	int fd;
-	u64 id;
-	char evt_path[MAXPATHLEN];
-	char dir_path[MAXPATHLEN];
-
-	if (debugfs_valid_mountpoint(debugfs_path))
-		return NULL;
-
-	sys_dir = opendir(debugfs_path);
-	if (!sys_dir)
-		return NULL;
-
-	for_each_subsystem(sys_dir, sys_dirent, sys_next) {
-
-		snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
-			 sys_dirent.d_name);
-		evt_dir = opendir(dir_path);
-		if (!evt_dir)
-			continue;
-
-		for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
-
-			snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
-				 evt_dirent.d_name);
-			fd = open(evt_path, O_RDONLY);
-			if (fd < 0)
-				continue;
-			if (read(fd, id_buf, sizeof(id_buf)) < 0) {
-				close(fd);
-				continue;
-			}
-			close(fd);
-			id = atoll(id_buf);
-			if (id == config) {
-				closedir(evt_dir);
-				closedir(sys_dir);
-				path = zalloc(sizeof(*path));
-				path->system = malloc(MAX_EVENT_LENGTH);
-				if (!path->system) {
-					free(path);
-					return NULL;
-				}
-				path->name = malloc(MAX_EVENT_LENGTH);
-				if (!path->name) {
-					free(path->system);
-					free(path);
-					return NULL;
-				}
-				strncpy(path->system, sys_dirent.d_name,
-					MAX_EVENT_LENGTH);
-				strncpy(path->name, evt_dirent.d_name,
-					MAX_EVENT_LENGTH);
-				return path;
-			}
-		}
-		closedir(evt_dir);
-	}
-
-	closedir(sys_dir);
-	return NULL;
-}
-
-#define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1)
 static const char *tracepoint_id_to_name(u64 config)
 {
 	static char buf[TP_PATH_LEN];
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 746d3fc..8b05b03 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -17,7 +17,6 @@ struct tracepoint_path {
 	struct tracepoint_path *next;
 };
 
-extern struct tracepoint_path *tracepoint_id_to_path(u64 config);
 extern bool have_tracepoints(struct list_head *evlist);
 
 const char *event_type(int type);
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index abc31a1..6bcb9a4 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -3,6 +3,7 @@
 
 #include <linux/kernel.h>
 #include <stdbool.h>
+#include <lk/util.h>
 
 enum parse_opt_type {
 	/* special types */
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 18/18] ras: Add RAS daemon
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (16 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 17/18] perf: Export tracepoint_id_to_path Borislav Petkov
@ 2011-04-23 16:28 ` Borislav Petkov
  2011-04-29 14:08 ` [PATCH 00/18] RAS daemon: Easter Eggs Edition Frederic Weisbecker
  18 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-23 16:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/Makefile     |    4 +
 tools/ras/Makefile |   16 ++
 tools/ras/rasd.c   |  440 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 460 insertions(+), 0 deletions(-)
 create mode 100644 tools/ras/Makefile
 create mode 100644 tools/ras/rasd.c

diff --git a/tools/Makefile b/tools/Makefile
index 60993bf..fb4fdb3 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -27,6 +27,9 @@ liblkperf: .FORCE
 libtrace: .FORCE
 	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1)
 
+ras: libtrace liblkperf liblk .FORCE
+	$(QUIET_SUBDIR0)ras/ $(QUIET_SUBDIR1)
+
 slabinfo: .FORCE
 	$(QUIET_SUBDIR0)slub/ $(QUIET_SUBDIR1)
 
@@ -48,6 +51,7 @@ clean:
 	$(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)lib/perf/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)ras/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)slub/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)power/x86/turbostat/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)usb/ $(QUIET_SUBDIR1) clean
diff --git a/tools/ras/Makefile b/tools/ras/Makefile
new file mode 100644
index 0000000..b9b1c23
--- /dev/null
+++ b/tools/ras/Makefile
@@ -0,0 +1,16 @@
+include ../scripts/Makefile.lib
+
+CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 -DNO_NEWT_SUPPORT $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
+ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+ALL_LDFLAGS = $(LDFLAGS)
+
+RASLIBS=$(LIB_OUTPUT)liblkperf.a $(LIB_OUTPUT)libtrace.a $(LIB_OUTPUT)liblk.a
+
+rasd: rasd.o
+	$(QUIET_CC)$(CC) $(ALL_CFLAGS) -o $@ $^ $(RASLIBS)
+
+%.o: %.c
+	$(QUIET_CC)$(CC) $(ALL_CFLAGS) -c $<
+
+clean:
+	rm -rf *.o rasd
diff --git a/tools/ras/rasd.c b/tools/ras/rasd.c
new file mode 100644
index 0000000..1bdf66b
--- /dev/null
+++ b/tools/ras/rasd.c
@@ -0,0 +1,440 @@
+/*
+ * Linux RAS daemon.
+ *
+ * Initial code reused from Linux Daemon Writing HOWTO
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+
+#include <lk/util.h>
+#include <lk/debugfs.h>
+#include <lk/thread_map.h>
+#include <lk/cpumap.h>
+#include <perf/evsel.h>
+#include <perf/evlist.h>
+#include <trace/trace-event.h>
+
+#include "../../include/linux/perf_event.h"
+#include "../../arch/x86/include/asm/mce.h"
+
+#undef DEBUG
+
+#ifdef DEBUG
+#define dbg(fmt, args...) \
+	fprintf(stderr, "DBG %s: " fmt "\n", __func__, ##args)
+#else
+#define dbg(fmt, args...) do { } while (0)
+#endif
+
+#define MMAP_PAGES		128
+#define MCE_TP			"mce/mce_record"
+
+#define PFX "rasd: "
+#define ras_err(fmt, args...)	error(PFX fmt, ##args)
+#define ras_die(fmt, args...)	die(PFX fmt, ##args)
+
+static struct event *mce_event;
+static struct thread_map *thread;
+static struct cpu_map *cpus;
+static struct perf_evlist *evlist;
+static struct perf_evsel *evsel;
+static struct mce m;
+static const char *dfs_root;
+
+const char *logf_path = "/var/log/ras.log";
+
+static unsigned long long read_file(const char *file, void *buf)
+{
+	unsigned long long size = 0;
+	int fd, r;
+
+	fd = open(file, O_RDONLY);
+	if (fd < 0)
+		die("Can't read '%s'", file);
+
+	do {
+		r = read(fd, buf, BUFSIZ);
+		if (r > 0)
+			size += r;
+	} while (r > 0);
+
+	close(fd);
+
+	return size;
+}
+
+static int parse_mce_event(void)
+{
+	struct stat st;
+	char *fmt_path, *fmt_buf, *tracing_dir;
+	int fsize, err = -EINVAL;
+
+	tracing_dir = get_tracing_file("events");
+	if (!tracing_dir) {
+		ras_err("Cannot get trace events dir!");
+		goto err_out;
+	}
+
+	dbg("Got %s", tracing_dir);
+
+	err = -ENOMEM;
+	fmt_path = malloc(MAXPATHLEN + sizeof(MCE_TP) + 10);
+	if (!fmt_path) {
+		ras_err("allocating %s string", MCE_TP);
+		goto err_event_format;
+	}
+
+	sprintf(fmt_path, "%s/%s/format", tracing_dir, MCE_TP);
+
+	err = stat(fmt_path, &st);
+	if (err < 0) {
+		ras_err("accessing %s", fmt_path);
+		goto err_free_fmt_path;
+	}
+
+	dbg("Format access %s ok", fmt_path);
+
+	fsize = get_filesize(fmt_path);
+
+	dbg("Format file size: %d", fsize);
+
+	err = -ENOMEM;
+	fmt_buf = malloc(fsize);
+	if (!fmt_buf) {
+		ras_err("allocating format buffer");
+		goto err_free_fmt_path;
+	}
+
+	if (!read_file(fmt_path, fmt_buf)) {
+		ras_err("reading in format file");
+		goto err_free_fmt_buf;
+	}
+
+	dbg("event format:\n%s", fmt_buf);
+
+	init_input_buf(fmt_buf, fsize);
+
+	err = -ENOMEM;
+	mce_event = alloc_event();
+	if (!mce_event) {
+		ras_err("allocating mce_event");
+		goto err_free_fmt_buf;
+	}
+
+	err = -EINVAL;
+	mce_event->name = event_read_name();
+	if (!mce_event->name) {
+		ras_err("reading event name");
+		goto err_free_event;
+	}
+
+	mce_event->id = event_read_id();
+	if (mce_event->id < 0) {
+		ras_err("reading event id");
+		goto err_free_event;
+	}
+
+	if (event_read_format(mce_event)) {
+		ras_err("reading event format");
+		goto err_free_event;
+	}
+
+	/*
+	 * we're done parsing the event, free temporarily used resources
+	 * and leave only mce_event.
+	 */
+	err = 0;
+	goto err_free_fmt_buf;
+
+err_free_event:
+	free(mce_event);
+
+err_free_fmt_buf:
+	free(fmt_buf);
+
+err_free_fmt_path:
+	free(fmt_path);
+
+err_event_format:
+	put_tracing_file(tracing_dir);
+
+err_out:
+	return err;
+}
+
+static void fill_mce_data(void *vbuf, size_t buflen)
+{
+	struct format_field *field;
+	char *buf = vbuf;
+#ifdef DEBUG
+	unsigned i;
+#endif
+
+	if (!buflen)
+		return;
+
+#ifdef DEBUG
+	dbg("buflen %lu", buflen);
+
+	for (i = 0; i < buflen; i++) {
+
+		if (!(i % 8) && i)
+			printf("\n");
+
+		printf("0x%2.2x ", *(unsigned char *)(buf + i));
+	}
+#endif
+
+	for (field = mce_event->format.fields; field; field = field->next) {
+		if ((size_t)(field->offset + field->size) > buflen)
+			warning("MCE buf truncated? (off: %d <-> buflen: %lu)",
+				field->offset, buflen);
+
+		dbg("field %s, offset: %d", field->name, field->offset);
+
+		if (!strncmp(field->name, "bank", 4))
+			m.bank = *(u8 *)(buf + field->offset);
+		else if (!strncmp(field->name, "status", 6))
+			m.status = *(u64 *)(buf + field->offset);
+		else if (!strncmp(field->name, "addr", 4))
+			m.addr = *(u64 *)(buf + field->offset);
+		else if (!strncmp(field->name, "misc", 4))
+			m.misc = *(u64 *)(buf + field->offset);
+		else if (!strncmp(field->name, "ip", 2))
+			m.ip = *(u64 *)(buf + field->offset);
+		else if (!strncmp(field->name, "cs", 2))
+			m.cs = *(u8 *)(buf + field->offset);
+		else if (!strncmp(field->name, "tsc", 3))
+			m.tsc = *(u64 *)(buf + field->offset);
+		else if (!strncmp(field->name, "cpu", 3))
+			m.cpu = *(u8 *)(buf + field->offset);
+		else
+			warning("skipping %s", field->name);
+	}
+}
+
+static struct perf_event_attr attr = {
+	.type	     = PERF_TYPE_TRACEPOINT,
+	.sample_type = PERF_SAMPLE_RAW,
+};
+
+static struct perf_evlist *mmap_tp(void)
+{
+	struct perf_evlist *evl;
+	int cpu;
+	char dfs_path[MAXPATHLEN];
+
+	attr.wakeup_events = 1;
+	attr.sample_period = 1;
+
+	thread = thread_map__new(-1, getpid());
+	if (!thread) {
+		ras_err("thread_map__new\n");
+		goto err_out;
+	}
+
+	cpus = cpu_map__new(NULL);
+	if (!cpus) {
+		ras_err("cpu_map__new\n");
+		goto err_free_thread;
+	}
+
+	evl = perf_evlist__new(cpus, thread);
+	if (!evl) {
+		ras_err("perf_evlist__new\n");
+		goto err_free_cpus;
+	}
+
+	evsel = perf_evsel__new(&attr, 0);
+	if (!evsel) {
+		ras_err("perf_evsel__new\n");
+		goto err_free_evlist;
+	}
+
+	perf_evlist__add(evl, evsel);
+
+	if (evsel->fd == NULL &&
+	    perf_evsel__alloc_fd(evsel, cpus->nr, thread->nr) < 0) {
+		ras_err("perf_evsel__alloc_fd\n");
+		goto err_free_evlist;
+	}
+
+	/*
+	 * debugfs_mount has to precede that since we rely
+	 * on dfs_root being properly set
+	 */
+	for (cpu = 0; cpu < cpus->nr; cpu++) {
+
+		memset(dfs_path, 0, MAXPATHLEN);
+
+		snprintf(dfs_path, MAXPATHLEN, "%s/%s%d", dfs_root, MCE_TP, cpu);
+
+		dbg("dfs_path: %s", dfs_path);
+
+		FD(evsel, cpu, 0) = open(dfs_path, O_RDWR, O_NONBLOCK);
+		if (FD(evsel, cpu, 0) < 0) {
+			ras_err("open perf event on cpu %d\n", cpu);
+			goto err_open_fds;
+		} else
+			dbg("cpu %d, fd %d", cpu, FD(evsel, cpu, 0));
+	}
+
+	if (perf_evlist__mmap(evl, 4, true) < 0) {
+		ras_err("perf_evlist__mmap\n");
+		goto err_open_fds;
+	}
+
+	return evl;
+
+err_open_fds:
+	for (; cpu >= 0; cpu--) {
+		close(FD(evsel, cpu, 0));
+		FD(evsel, cpu, 0) = -1;
+	}
+	perf_evsel__free_fd(evsel);
+
+err_free_evlist:
+	perf_evlist__delete(evl);
+
+err_free_cpus:
+	cpu_map__delete(cpus);
+
+err_free_thread:
+	thread_map__delete(thread);
+
+err_out:
+	return NULL;
+
+}
+
+static int ras_init(void)
+{
+	int err = 0;
+
+	fprintf(stderr, PFX "Starting daemon.\n");
+
+	dfs_root = debugfs_mount(NULL);
+	if (!dfs_root) {
+		error("Cannot mount debugfs, exiting... ");
+		return 1;
+	}
+
+	err = parse_mce_event();
+	if (err)
+		return err;
+
+	evlist = mmap_tp();
+	if (!evlist) {
+		ras_err("mmap_tp\n");
+		return 1;
+	}
+
+	return 0;
+}
+
+static void unmap_tp(void)
+{
+	perf_evlist__munmap(evlist);
+	perf_evsel__close_fd(evsel, evlist->cpus->nr, thread->nr);
+	perf_evlist__delete(evlist);
+	cpu_map__delete(cpus);
+	thread_map__delete(thread);
+}
+
+int main(void)
+{
+	union perf_event *event;
+#ifndef DEBUG
+	pid_t pid, sid;
+#endif
+	FILE *logfile = NULL;
+	int err = 0;
+
+#ifndef DEBUG
+	pid = fork();
+	if (pid < 0) {
+		error(PFX "Error forking daemon thread.");
+		exit(EXIT_FAILURE);
+	}
+
+	/* parent can disappear now */
+	if (pid > 0)
+		exit(EXIT_SUCCESS);
+
+	umask(0);
+
+	sid = setsid();
+	if (sid < 0) {
+		error(PFX "Error creating session.");
+		exit(EXIT_FAILURE);
+	}
+
+	if (chdir("/") < 0) {
+		error(PFX "Error chdir to /");
+		exit(EXIT_FAILURE);
+	}
+#endif
+	logfile = fopen(logf_path, "a");
+	if (!logfile) {
+		error(PFX "Error opening logs: %s\n", strerror(errno));
+		err = errno;
+		goto exit;
+	}
+
+#ifndef DEBUG
+	close(STDIN_FILENO);
+	close(STDOUT_FILENO);
+	close(STDERR_FILENO);
+#endif
+
+	err = ras_init();
+	if (err)
+		goto out;
+
+	for (;;) {
+		int cpu;
+
+		for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
+			while ((event = perf_evlist__read_on_cpu(evlist, cpu))) {
+				struct perf_sample s;
+
+				perf_event__parse_sample(event, attr.sample_type,
+							 false, &s);
+
+				fill_mce_data(s.raw_data, s.raw_size);
+
+				dbg("Got MCE, cpu: %d, status: 0x%016llx, addr: 0x%016llx\n",
+				    m.cpu, m.status, m.addr);
+
+				fprintf(logfile,
+					"MCE on cpu %d, status: 0x%016llx, addr: 0x%016llx\n",
+					m.cpu, m.status, m.addr);
+				fflush(logfile);
+			}
+		}
+
+		dbg("polling fds");
+		poll(evlist->pollfd, evlist->nr_fds, -1);
+	}
+
+	goto cleanup;
+
+out:
+	free(mce_event);
+	unmap_tp();
+
+cleanup:
+	fclose(logfile);
+
+exit:
+	return err;
+
+}
-- 
1.7.4.rc2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH 02/18] perf: Add persistent event facilities
  2011-04-23 16:28 ` [PATCH 02/18] perf: Add persistent event facilities Borislav Petkov
@ 2011-04-26 10:57   ` Peter Zijlstra
  2011-04-26 12:45     ` Ingo Molnar
  0 siblings, 1 reply; 28+ messages in thread
From: Peter Zijlstra @ 2011-04-26 10:57 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, Steven Rostedt,
	Frederic Weisbecker, Tony Luck, Mauro Carvalho Chehab,
	David Ahern, EDAC devel, LKML, Borislav Petkov

On Sat, 2011-04-23 at 18:28 +0200, Borislav Petkov wrote:
> From: Borislav Petkov <borislav.petkov@amd.com>
> 
> Add a barebones implementation for registering persistent events with
> perf. For that, we don't destroy the buffers when they're unmapped and
> we map them read-only so that multiple agents can access them.
> 
> Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
> ---
>  include/linux/perf_event.h |   22 ++++++++++++++++-
>  kernel/events/Makefile     |    2 +-
>  kernel/events/core.c       |   30 ++++++++++++++++++----
>  kernel/events/persistent.c |   56 ++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 102 insertions(+), 8 deletions(-)
>  create mode 100644 kernel/events/persistent.c
> 
> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> index ee9f1e7..37bfae1 100644
> --- a/include/linux/perf_event.h
> +++ b/include/linux/perf_event.h
> @@ -216,8 +216,9 @@ struct perf_event_attr {
>                                 precise_ip     :  2, /* skid constraint       */
>                                 mmap_data      :  1, /* non-exec mmap data    */
>                                 sample_id_all  :  1, /* sample_type all events */
> +                               persistent     :  1, /* event always on */

But how will you find it again?

Persistent yells filesystem to me, and while we didn't use relayfs for
various reasons, I think we do need something like it at the current
stage.



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 02/18] perf: Add persistent event facilities
  2011-04-26 10:57   ` Peter Zijlstra
@ 2011-04-26 12:45     ` Ingo Molnar
  2011-04-26 14:05       ` Borislav Petkov
  0 siblings, 1 reply; 28+ messages in thread
From: Ingo Molnar @ 2011-04-26 12:45 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Borislav Petkov, Arnaldo Carvalho de Melo, Steven Rostedt,
	Frederic Weisbecker, Tony Luck, Mauro Carvalho Chehab,
	David Ahern, EDAC devel, LKML, Borislav Petkov


* Peter Zijlstra <peterz@infradead.org> wrote:

> On Sat, 2011-04-23 at 18:28 +0200, Borislav Petkov wrote:
> > From: Borislav Petkov <borislav.petkov@amd.com>
> > 
> > Add a barebones implementation for registering persistent events with
> > perf. For that, we don't destroy the buffers when they're unmapped and
> > we map them read-only so that multiple agents can access them.
> > 
> > Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
> > ---
> >  include/linux/perf_event.h |   22 ++++++++++++++++-
> >  kernel/events/Makefile     |    2 +-
> >  kernel/events/core.c       |   30 ++++++++++++++++++----
> >  kernel/events/persistent.c |   56 ++++++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 102 insertions(+), 8 deletions(-)
> >  create mode 100644 kernel/events/persistent.c
> > 
> > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> > index ee9f1e7..37bfae1 100644
> > --- a/include/linux/perf_event.h
> > +++ b/include/linux/perf_event.h
> > @@ -216,8 +216,9 @@ struct perf_event_attr {
> >                                 precise_ip     :  2, /* skid constraint       */
> >                                 mmap_data      :  1, /* non-exec mmap data    */
> >                                 sample_id_all  :  1, /* sample_type all events */
> > +                               persistent     :  1, /* event always on */
> 
> But how will you find it again?
> 
> Persistent yells filesystem to me, and while we didn't use relayfs for 
> various reasons, I think we do need something like it at the current stage.

eventfs or sysfs?

We need VFS space for event hierarchy enumeration anyway (and move the current 
debugfs bits there). Persistent events could show up in that hiearachy as well.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 02/18] perf: Add persistent event facilities
  2011-04-26 12:45     ` Ingo Molnar
@ 2011-04-26 14:05       ` Borislav Petkov
  0 siblings, 0 replies; 28+ messages in thread
From: Borislav Petkov @ 2011-04-26 14:05 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Peter Zijlstra, Borislav Petkov, Arnaldo Carvalho de Melo,
	Steven Rostedt, Frederic Weisbecker, Tony Luck,
	Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML

On Tue, Apr 26, 2011 at 08:45:10AM -0400, Ingo Molnar wrote:
> 
> * Peter Zijlstra <peterz@infradead.org> wrote:
> 
> > On Sat, 2011-04-23 at 18:28 +0200, Borislav Petkov wrote:
> > > From: Borislav Petkov <borislav.petkov@amd.com>
> > > 
> > > Add a barebones implementation for registering persistent events with
> > > perf. For that, we don't destroy the buffers when they're unmapped and
> > > we map them read-only so that multiple agents can access them.
> > > 
> > > Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
> > > ---
> > >  include/linux/perf_event.h |   22 ++++++++++++++++-
> > >  kernel/events/Makefile     |    2 +-
> > >  kernel/events/core.c       |   30 ++++++++++++++++++----
> > >  kernel/events/persistent.c |   56 ++++++++++++++++++++++++++++++++++++++++++++
> > >  4 files changed, 102 insertions(+), 8 deletions(-)
> > >  create mode 100644 kernel/events/persistent.c
> > > 
> > > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> > > index ee9f1e7..37bfae1 100644
> > > --- a/include/linux/perf_event.h
> > > +++ b/include/linux/perf_event.h
> > > @@ -216,8 +216,9 @@ struct perf_event_attr {
> > >                                 precise_ip     :  2, /* skid constraint       */
> > >                                 mmap_data      :  1, /* non-exec mmap data    */
> > >                                 sample_id_all  :  1, /* sample_type all events */
> > > +                               persistent     :  1, /* event always on */
> > 
> > But how will you find it again?
> > 
> > Persistent yells filesystem to me, and while we didn't use relayfs for 
> > various reasons, I think we do need something like it at the current stage.
> 
> eventfs or sysfs?
> 
> We need VFS space for event hierarchy enumeration anyway (and move the current 
> debugfs bits there). Persistent events could show up in that hiearachy as well.

I think we talked about this already in conjunction with moving event
hierarchy to sysfs - there you can have a "persistent" node too so you
can find it.

Here's what we talked about then:

https://lkml.org/lkml/2010/11/11/10

this and the following messages.

-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/18] RAS daemon: Easter Eggs Edition
  2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
                   ` (17 preceding siblings ...)
  2011-04-23 16:28 ` [PATCH 18/18] ras: Add RAS daemon Borislav Petkov
@ 2011-04-29 14:08 ` Frederic Weisbecker
  2011-04-29 14:25   ` Borislav Petkov
  2011-04-29 14:39   ` Steven Rostedt
  18 siblings, 2 replies; 28+ messages in thread
From: Frederic Weisbecker @ 2011-04-29 14:08 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, Peter Zijlstra,
	Steven Rostedt, Tony Luck, Mauro Carvalho Chehab, David Ahern,
	EDAC devel, LKML, Borislav Petkov

On Sat, Apr 23, 2011 at 06:28:02PM +0200, Borislav Petkov wrote:
> From: Borislav Petkov <borislav.petkov@amd.com>
> 
> Ok, here's yet another version of the RAS daemon patchset. This one
> changes all the event handling to how it is done in test__basic_mmap(),
> as acme suggested. Patchset is against tip/perf/core from today.
> 
> With this I can inject an mce using the python script below (yeah, work
> in progress in itself):
> 
> $ mcegen.py -i sw
> 
> 	[ this will inject a random MCE using the mce_amd_inj.ko module ]
> 
> and in /var/log/ras.log I get:
> 
> MCE on cpu 0, status: 0xf200210000000853, addr: 0x0000000000000000
> MCE on cpu 0, status: 0x9800400000000015, addr: 0x0000000000000000
> MCE on cpu 0, status: 0xfc00200000050e0f, addr: 0x0000000000000000
> MCE on cpu 0, status: 0x98004100001c010b, addr: 0x0000000000000000
> MCE on cpu 0, status: 0xbc00200000000843, addr: 0x0000000000000000
> MCE on cpu 0, status: 0xda00410000080e0f, addr: 0x0000000000000000
> 
> Yep, it is still raw info but you can do almost anything with that info
> in userspace.
> 
> Next on the TODO list is changing the tracepoint to convey the decoded
> info too which should be a fairly simple task to do.
> 
> So we've got the basic design hammered out methinks, the persistent
> event is off by default for now and since rebasing this pile is always a
> great PITA for me due to other developments in tools/perf, I'd like it
> very much if I could offload it in -tip soon.

If you want to accelerate that, I suggest you cut your patchset into smaller
sets and focus on merging them piece by piece. Few people are going to review
18 patches at once. They may plan to scatter their review over days but
that doesn't scale well, and it naturally reduces the number of reviewers.

You could start with exporting trace things into tools/trace, post the
few concerned patches and iterate them until everyone is happy. Then
switch to another subset of the big thing.

Hm?

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/18] RAS daemon: Easter Eggs Edition
  2011-04-29 14:08 ` [PATCH 00/18] RAS daemon: Easter Eggs Edition Frederic Weisbecker
@ 2011-04-29 14:25   ` Borislav Petkov
  2011-04-29 14:31     ` Ingo Molnar
  2011-04-29 14:39   ` Steven Rostedt
  1 sibling, 1 reply; 28+ messages in thread
From: Borislav Petkov @ 2011-04-29 14:25 UTC (permalink / raw)
  To: Frederic Weisbecker
  Cc: Borislav Petkov, Arnaldo Carvalho de Melo, Ingo Molnar,
	Peter Zijlstra, Steven Rostedt, Tony Luck, Mauro Carvalho Chehab,
	David Ahern, EDAC devel, LKML

On Fri, Apr 29, 2011 at 10:08:48AM -0400, Frederic Weisbecker wrote:
> 
> If you want to accelerate that, I suggest you cut your patchset into smaller
> sets and focus on merging them piece by piece. Few people are going to review
> 18 patches at once. They may plan to scatter their review over days but
> that doesn't scale well, and it naturally reduces the number of reviewers.
> 
> You could start with exporting trace things into tools/trace, post the
> few concerned patches and iterate them until everyone is happy. Then
> switch to another subset of the big thing.

Hi Frederic,

I can definitely do that. I just wanted to know before I do it though,
whether the general direction is ok and whether people are fine with the
changes, i.e. Arnaldo, Ingo, Peter, Steven, any reactions? If yes, I can
get to work and split the big pile into more digestible pieces.

Thanks.

-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/18] RAS daemon: Easter Eggs Edition
  2011-04-29 14:25   ` Borislav Petkov
@ 2011-04-29 14:31     ` Ingo Molnar
  2011-04-29 17:35       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 28+ messages in thread
From: Ingo Molnar @ 2011-04-29 14:31 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Frederic Weisbecker, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Steven Rostedt, Tony Luck, Mauro Carvalho Chehab, David Ahern,
	EDAC devel, LKML


* Borislav Petkov <bp@amd64.org> wrote:

> On Fri, Apr 29, 2011 at 10:08:48AM -0400, Frederic Weisbecker wrote:
> > 
> > If you want to accelerate that, I suggest you cut your patchset into 
> > smaller sets and focus on merging them piece by piece. Few people are going 
> > to review 18 patches at once. They may plan to scatter their review over 
> > days but that doesn't scale well, and it naturally reduces the number of 
> > reviewers.
> > 
> > You could start with exporting trace things into tools/trace, post the few 
> > concerned patches and iterate them until everyone is happy. Then switch to 
> > another subset of the big thing.
> 
> Hi Frederic,
> 
> I can definitely do that. I just wanted to know before I do it though, 
> whether the general direction is ok and whether people are fine with the 
> changes, i.e. Arnaldo, Ingo, Peter, Steven, any reactions? If yes, I can get 
> to work and split the big pile into more digestible pieces.

I definitely like the general approach, it's a big step forward from mcelog. 
Might make sense to progress to the small digestible patches stage to get out 
the detailed reviews?

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/18] RAS daemon: Easter Eggs Edition
  2011-04-29 14:08 ` [PATCH 00/18] RAS daemon: Easter Eggs Edition Frederic Weisbecker
  2011-04-29 14:25   ` Borislav Petkov
@ 2011-04-29 14:39   ` Steven Rostedt
  1 sibling, 0 replies; 28+ messages in thread
From: Steven Rostedt @ 2011-04-29 14:39 UTC (permalink / raw)
  To: Frederic Weisbecker
  Cc: Borislav Petkov, Arnaldo Carvalho de Melo, Ingo Molnar,
	Peter Zijlstra, Tony Luck, Mauro Carvalho Chehab, David Ahern,
	EDAC devel, LKML, Borislav Petkov

On Fri, 2011-04-29 at 16:08 +0200, Frederic Weisbecker wrote:
> On Sat, Apr 23, 2011 at 06:28:02PM +0200, Borislav Petkov wrote:

> If you want to accelerate that, I suggest you cut your patchset into smaller
> sets and focus on merging them piece by piece. Few people are going to review
> 18 patches at once. They may plan to scatter their review over days but
> that doesn't scale well, and it naturally reduces the number of reviewers.

True, I tend to ignore almost anything more than 8 patches. Or I'll
start reviewing them, get 5 patches into it and then have to work on
other things, and never finish the rest.

-- Steve



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/18] RAS daemon: Easter Eggs Edition
  2011-04-29 14:31     ` Ingo Molnar
@ 2011-04-29 17:35       ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 28+ messages in thread
From: Arnaldo Carvalho de Melo @ 2011-04-29 17:35 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Borislav Petkov, Frederic Weisbecker, Peter Zijlstra,
	Steven Rostedt, Tony Luck, Mauro Carvalho Chehab, David Ahern,
	EDAC devel, LKML

Em Fri, Apr 29, 2011 at 04:31:45PM +0200, Ingo Molnar escreveu:
> 
> * Borislav Petkov <bp@amd64.org> wrote:
> 
> > On Fri, Apr 29, 2011 at 10:08:48AM -0400, Frederic Weisbecker wrote:
> > > 
> > > If you want to accelerate that, I suggest you cut your patchset into 
> > > smaller sets and focus on merging them piece by piece. Few people are going 
> > > to review 18 patches at once. They may plan to scatter their review over 
> > > days but that doesn't scale well, and it naturally reduces the number of 
> > > reviewers.
> > > 
> > > You could start with exporting trace things into tools/trace, post the few 
> > > concerned patches and iterate them until everyone is happy. Then switch to 
> > > another subset of the big thing.
> > 
> > Hi Frederic,
> > 
> > I can definitely do that. I just wanted to know before I do it though, 
> > whether the general direction is ok and whether people are fine with the 
> > changes, i.e. Arnaldo, Ingo, Peter, Steven, any reactions? If yes, I can get 
> > to work and split the big pile into more digestible pieces.
> 
> I definitely like the general approach, it's a big step forward from mcelog. 
> Might make sense to progress to the small digestible patches stage to get out 
> the detailed reviews?

+1
 
> Thanks,
> 
> 	Ingo

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 09/18] perf: Drop redundant FD macro definitions
  2011-04-23 16:28 ` [PATCH 09/18] perf: Drop redundant FD macro definitions Borislav Petkov
@ 2011-07-25 15:04   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 28+ messages in thread
From: Arnaldo Carvalho de Melo @ 2011-07-25 15:04 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Ingo Molnar, Peter Zijlstra, Steven Rostedt, Frederic Weisbecker,
	Tony Luck, Mauro Carvalho Chehab, David Ahern, EDAC devel, LKML,
	Borislav Petkov

Em Sat, Apr 23, 2011 at 06:28:11PM +0200, Borislav Petkov escreveu:
> From: Borislav Petkov <borislav.petkov@amd.com>
> 
> Put a single define in the util/util.h header which should be generic
> enough and included by all builtin commands.

I'll apply this one, but will move those definitions to evsel.h, as they
operate on an evlist instance (e->fd).

- Arnaldo
 
> Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
> ---
>  tools/perf/builtin-record.c |    2 --
>  tools/perf/builtin-top.c    |    2 --
>  tools/perf/util/evlist.c    |    3 ---
>  tools/perf/util/evsel.c     |    2 --
>  tools/perf/util/util.h      |    3 +++
>  5 files changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index 4165382..4497a38 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -30,8 +30,6 @@
>  #include <sched.h>
>  #include <sys/mman.h>
>  
> -#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
> -
>  enum write_mode_t {
>  	WRITE_FORCE,
>  	WRITE_APPEND
> diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
> index 7e3d6e3..7fd50c1 100644
> --- a/tools/perf/builtin-top.c
> +++ b/tools/perf/builtin-top.c
> @@ -62,8 +62,6 @@
>  #include <linux/unistd.h>
>  #include <linux/types.h>
>  
> -#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
> -
>  static struct perf_top top = {
>  	.count_filter		= 5,
>  	.delay_secs		= 2,
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index 45da8d1..65a8031 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -19,9 +19,6 @@
>  #include <linux/bitops.h>
>  #include <linux/hash.h>
>  
> -#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
> -#define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
> -
>  void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
>  		       struct thread_map *threads)
>  {
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index d6fd59b..13ee267 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -13,8 +13,6 @@
>  #include "cpumap.h"
>  #include "thread_map.h"
>  
> -#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
> -
>  void perf_evsel__init(struct perf_evsel *evsel,
>  		      struct perf_event_attr *attr, int idx)
>  {
> diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
> index fc78428..c32d66d 100644
> --- a/tools/perf/util/util.h
> +++ b/tools/perf/util/util.h
> @@ -39,6 +39,9 @@
>  /* Approximation of the length of the decimal representation of this type. */
>  #define decimal_length(x)	((int)(sizeof(x) * 2.56 + 0.5) + 1)
>  
> +#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
> +#define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
> +
>  #define _ALL_SOURCE 1
>  #define _GNU_SOURCE 1
>  #define _BSD_SOURCE 1
> -- 
> 1.7.4.rc2

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2011-07-25 15:05 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-23 16:28 [PATCH 00/18] RAS daemon: Easter Eggs Edition Borislav Petkov
2011-04-23 16:28 ` [PATCH 01/18] perf: Start the restructuring Borislav Petkov
2011-04-23 16:28 ` [PATCH 02/18] perf: Add persistent event facilities Borislav Petkov
2011-04-26 10:57   ` Peter Zijlstra
2011-04-26 12:45     ` Ingo Molnar
2011-04-26 14:05       ` Borislav Petkov
2011-04-23 16:28 ` [PATCH 03/18] x86, mce: Add persistent MCE event Borislav Petkov
2011-04-23 16:28 ` [PATCH 04/18] x86, mce: Have MCE persistent event off by default for now Borislav Petkov
2011-04-23 16:28 ` [PATCH 05/18] perf: Add Makefile.lib Borislav Petkov
2011-04-23 16:28 ` [PATCH 06/18] tools: Add a toplevel Makefile Borislav Petkov
2011-04-23 16:28 ` [PATCH 07/18] perf: Export trace-event utils Borislav Petkov
2011-04-23 16:28 ` [PATCH 08/18] perf: Remove duplicate enum trace_flag_type Borislav Petkov
2011-04-23 16:28 ` [PATCH 09/18] perf: Drop redundant FD macro definitions Borislav Petkov
2011-07-25 15:04   ` Arnaldo Carvalho de Melo
2011-04-23 16:28 ` [PATCH 10/18] perf: Export debugfs utilities Borislav Petkov
2011-04-23 16:28 ` [PATCH 11/18] perf: Export cpumap.[ch] Borislav Petkov
2011-04-23 16:28 ` [PATCH 12/18] perf: Export thread_map.[ch] Borislav Petkov
2011-04-23 16:28 ` [PATCH 13/18] perf: Export evsel.[ch] Borislav Petkov
2011-04-23 16:28 ` [PATCH 14/18] perf: Export cgroup.[ch] Borislav Petkov
2011-04-23 16:28 ` [PATCH 15/18] perf: Export evlist.[ch] Borislav Petkov
2011-04-23 16:28 ` [PATCH 16/18] perf: Export ctype.c Borislav Petkov
2011-04-23 16:28 ` [PATCH 17/18] perf: Export tracepoint_id_to_path Borislav Petkov
2011-04-23 16:28 ` [PATCH 18/18] ras: Add RAS daemon Borislav Petkov
2011-04-29 14:08 ` [PATCH 00/18] RAS daemon: Easter Eggs Edition Frederic Weisbecker
2011-04-29 14:25   ` Borislav Petkov
2011-04-29 14:31     ` Ingo Molnar
2011-04-29 17:35       ` Arnaldo Carvalho de Melo
2011-04-29 14:39   ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.