Skip to contentSkip to conversation

Fix mman macros using mman-fix.h

PATCH In review Wang Nan 2 participants 8 messages Sep 6, 2016 perf events

lore
Share & tools
lore

Wang Nan

author
#0 lore raw

cover Fix mman macros using mman-fix.h

Macros in mman like MAP_HUGETLB are missed in some old systems, causes building error like this:

CC /tmp/build/perf/arch/x86/util/perf_regs.o
util/event.c: In function 'perf_event__synthesize_mmap_events':
util/event.c:350: error: 'MAP_HUGETLB' undeclared (first use in this function) util/event.c:350: error: (Each undeclared identifier is reported only once
util/event.c:350: error: for each function it appears in.)

The first patch generates mman-fix.h for each arch, the second patch fixes these macros use mman-fix.h.

Wang Nan (2):
perf tools: Introduce memory mapping macros in mman-fix.h perf tools: Fix mman macros using mman-fix.h

 tools/arch/alpha/include/uapi/asm/mman-fix.h      | 38 ++++++++++++++
 tools/arch/arm/include/uapi/asm/mman-fix.h        |  5 ++
 tools/arch/arm64/include/uapi/asm/mman-fix.h      |  5 ++
 tools/arch/frv/include/uapi/asm/mman-fix.h        |  5 ++
 tools/arch/h8300/include/uapi/asm/mman-fix.h      |  5 ++
 tools/arch/hexagon/include/uapi/asm/mman-fix.h    |  5 ++
 tools/arch/ia64/include/uapi/asm/mman-fix.h       |  5 ++
 tools/arch/m32r/include/uapi/asm/mman-fix.h       |  5 ++
 tools/arch/microblaze/include/uapi/asm/mman-fix.h |  5 ++
 tools/arch/mips/include/uapi/asm/mman-fix.h       | 41 +++++++++++++++
 tools/arch/mn10300/include/uapi/asm/mman-fix.h    |  5 ++
 tools/arch/parisc/include/uapi/asm/mman-fix.h     | 38 ++++++++++++++
 tools/arch/powerpc/include/uapi/asm/mman-fix.h    | 11 ++++
 tools/arch/s390/include/uapi/asm/mman-fix.h       |  5 ++
 tools/arch/score/include/uapi/asm/mman-fix.h      |  5 ++
 tools/arch/sh/include/uapi/asm/mman-fix.h         |  5 ++
 tools/arch/sparc/include/uapi/asm/mman-fix.h      | 11 ++++
 tools/arch/tile/include/uapi/asm/mman-fix.h       | 11 ++++
 tools/arch/x86/include/uapi/asm/mman-fix.h        |  8 +++
 tools/arch/xtensa/include/uapi/asm/mman-fix.h     | 38 ++++++++++++++
 tools/include/uapi/asm-generic/mman-fix.h         | 46 +++++++++++++++++
 tools/perf/MANIFEST                               |  2 +
 tools/perf/trace/beauty/mmap.c                    | 63 +----------------------
 tools/perf/util/event.c                           |  5 +-
 tools/perf/util/map.c                             |  3 +-
 25 files changed, 307 insertions(+), 68 deletions(-)
 create mode 100644 tools/arch/alpha/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/arm/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/arm64/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/frv/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/h8300/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/hexagon/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/ia64/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/m32r/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/microblaze/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/mips/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/mn10300/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/parisc/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/powerpc/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/s390/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/score/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/sh/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/sparc/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/tile/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/x86/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/xtensa/include/uapi/asm/mman-fix.h
 create mode 100644 tools/include/uapi/asm-generic/mman-fix.h
Signature · 1 line
1.8.3.4
author
#1 lore raw

PATCH 1/2 perf tools: Introduce memory mapping macros in mman-fix.h

tools/perf/trace/beauty/mmap.c, tools/perf/util/event.c and tools/perf/util/map.c depend on several macros in mman.h, which are lost on old systems like ubuntu 12.04. They are architecture dependened macros. Importing ./arch/*/include/uapi/asm/mman.h into tools/ is not easy because mman.h for some unusual archs (like tile) have extra dependencies.

This patch introduces only required macros into mman-fix.h. Macros list is gotten from tools/perf/trace/beauty/mmap.c.

This patch is gnerated using following bash script:

#!/bin/bash

function begin_mman_fix_header()
{
echo "#ifndef $1" > $2
echo "#define $1" >> $2
echo "#include <sys/mman.h>" >> $2
}

function finish_mman_fix_header()
{
echo "#endif // $1" >> $2
echo "Finish writing $2"
}

function build_mman_fix_header()
{
guard=$1
shift
target=$1
shift
begin_mman_fix_header $guard $target
for src in $@
do
if [ -f $src ]
then
for macro in $macros
do
if grep '#define[ \t]*'$macro $src > /dev/null 2>&1
then
echo "#ifndef $macro" >> $target
grep '#define[ \t]*'$macro $src | sed 's/[ \t]*\/\*.*$//g' >> $target echo "#endif" >> $target
fi
done
fi
done
}

macros=grep ifndef tools/perf/trace/beauty/mmap.c | awk '{print $2}'

baseheader=tools/include/uapi/asm-generic/mman-fix.h
build_mman_fix_header __TOOLS_UAPI_ASM_MMAN_FIX_H $baseheader include/uapi/asm-generic/mman* echo "#ifndef MAP_UNINITIALIZED" >> $baseheader
echo "#define MAP_UNINITIALIZED 0x4000000" >> $baseheader
echo "#endif" >> $baseheader
finish_mman_fix_header __TOOLS_UAPI_ASM_MMAN_FIX_H $baseheader

archs=ls tools/arch
for arch in $archs
do
archheader=tools/arch/$arch/include/uapi/asm/mman-fix.h
if [ ! -d tools/arch/$arch/include/uapi/asm ]
then
mkdir -p tools/arch/$arch/include/uapi/asm
fi
uppercase=echo $arch | awk '{print toupper($0)}'
build_mman_fix_header TOOLS_ARCH_${uppercase}_UAPI_ASM_MMAN_FIX_H $archheader arch/$arch/include/uapi/asm/mman.h echo "#include <asm-generic/mman-fix.h>" >> $archheader
finish_mman_fix_header TOOLS_ARCH_${uppercase}_UAPI_ASM_MMAN_FIX_H $archheader
done

Cc Nilay Vaish <[email protected]>
Cc Hou Pengyang <[email protected]>
Cc He Kuang <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/arch/alpha/include/uapi/asm/mman-fix.h      | 38 +++++++++++++++++++
 tools/arch/arm/include/uapi/asm/mman-fix.h        |  5 +++
 tools/arch/arm64/include/uapi/asm/mman-fix.h      |  5 +++
 tools/arch/frv/include/uapi/asm/mman-fix.h        |  5 +++
 tools/arch/h8300/include/uapi/asm/mman-fix.h      |  5 +++
 tools/arch/hexagon/include/uapi/asm/mman-fix.h    |  5 +++
 tools/arch/ia64/include/uapi/asm/mman-fix.h       |  5 +++
 tools/arch/m32r/include/uapi/asm/mman-fix.h       |  5 +++
 tools/arch/microblaze/include/uapi/asm/mman-fix.h |  5 +++
 tools/arch/mips/include/uapi/asm/mman-fix.h       | 41 ++++++++++++++++++++
 tools/arch/mn10300/include/uapi/asm/mman-fix.h    |  5 +++
 tools/arch/parisc/include/uapi/asm/mman-fix.h     | 38 +++++++++++++++++++
 tools/arch/powerpc/include/uapi/asm/mman-fix.h    | 11 ++++++
 tools/arch/s390/include/uapi/asm/mman-fix.h       |  5 +++
 tools/arch/score/include/uapi/asm/mman-fix.h      |  5 +++
 tools/arch/sh/include/uapi/asm/mman-fix.h         |  5 +++
 tools/arch/sparc/include/uapi/asm/mman-fix.h      | 11 ++++++
 tools/arch/tile/include/uapi/asm/mman-fix.h       | 11 ++++++
 tools/arch/x86/include/uapi/asm/mman-fix.h        |  8 ++++
 tools/arch/xtensa/include/uapi/asm/mman-fix.h     | 38 +++++++++++++++++++
 tools/include/uapi/asm-generic/mman-fix.h         | 46 +++++++++++++++++++++++
 tools/perf/MANIFEST                               |  2 +
 22 files changed, 304 insertions(+)
 create mode 100644 tools/arch/alpha/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/arm/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/arm64/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/frv/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/h8300/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/hexagon/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/ia64/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/m32r/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/microblaze/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/mips/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/mn10300/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/parisc/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/powerpc/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/s390/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/score/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/sh/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/sparc/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/tile/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/x86/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/xtensa/include/uapi/asm/mman-fix.h
 create mode 100644 tools/include/uapi/asm-generic/mman-fix.h
tools/arch/alpha/include/uapi/asm/mman-fix.h new file +38 -0
new file mode 100644
index 0000000..f807a71
@@ -0,0 +1,38 @@
+#ifndef TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x8
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x100
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x10
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x80000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x100000
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
tools/arch/arm/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..a29dae1
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
tools/arch/arm64/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..e50c0d1
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
tools/arch/frv/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..8c2eb44
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
tools/arch/h8300/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..e639fe6
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
tools/arch/hexagon/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..dda9359
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
tools/arch/ia64/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..1e98f36
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
tools/arch/m32r/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..74aa94d
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
tools/arch/microblaze/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..90b7a53
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
tools/arch/mips/include/uapi/asm/mman-fix.h new file +41 -0

41 lines not on this page · raw message

tools/arch/mn10300/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..86a2903
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
tools/arch/parisc/include/uapi/asm/mman-fix.h new file +38 -0
new file mode 100644
index 0000000..c157a03
@@ -0,0 +1,38 @@
+#ifndef TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x8
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x04
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x10
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x40000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x80000
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   65
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 66
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	67
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	68
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   69
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	70
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
tools/arch/powerpc/include/uapi/asm/mman-fix.h new file +11 -0
new file mode 100644
index 0000000..4b552fa
@@ -0,0 +1,11 @@
+#ifndef TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_STACK
+#define MAP_STACK	0x20000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x40000
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
tools/arch/s390/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..d7755dd
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
tools/arch/score/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..97ad192
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
tools/arch/sh/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..d17bca8
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
tools/arch/sparc/include/uapi/asm/mman-fix.h new file +11 -0
new file mode 100644
index 0000000..3ac4ba0
@@ -0,0 +1,11 @@
+#ifndef TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_STACK
+#define MAP_STACK	0x20000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x40000
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
tools/arch/tile/include/uapi/asm/mman-fix.h new file +11 -0
new file mode 100644
index 0000000..105a3b0e
@@ -0,0 +1,11 @@
+#ifndef TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_STACK
+#define MAP_STACK	MAP_GROWSDOWN
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x4000
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
tools/arch/x86/include/uapi/asm/mman-fix.h new file +8 -0
new file mode 100644
index 0000000..0cda2bf
@@ -0,0 +1,8 @@
+#ifndef TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_32BIT
+#define MAP_32BIT	0x40
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
tools/arch/xtensa/include/uapi/asm/mman-fix.h new file +38 -0
new file mode 100644
index 0000000..9ec9051
@@ -0,0 +1,38 @@
+#ifndef TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x10
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x010
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x0800
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x40000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x80000
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
tools/include/uapi/asm-generic/mman-fix.h new file +46 -0

46 lines not on this page · raw message

tools/perf/MANIFEST +2 -0
index ff200c6..56ac24f 100644
@@ -66,6 +66,7 @@ tools/include/linux/hash.h
 tools/include/linux/kernel.h
 tools/include/linux/list.h
 tools/include/linux/log2.h
+tools/include/uapi/asm-generic/mman-fix.h
 tools/include/uapi/linux/bpf.h
 tools/include/uapi/linux/bpf_common.h
 tools/include/uapi/linux/hw_breakpoint.h
@@ -80,3 +81,4 @@ tools/include/linux/err.h
 tools/include/linux/bitmap.h
 tools/include/linux/time64.h
 tools/arch/*/include/uapi/asm/perf_regs.h
+tools/arch/*/include/uapi/asm/mman-fix.h
Signature · 1 line
1.8.3.4
#2 lore raw

Re: [PATCH 1/2] perf tools: Introduce memory mapping macros in mman-fix.h

Em Tue, Sep 06, 2016 at 05:48:51AM +0000, Wang Nan escreveu:

Quoted 3 lines

tools/perf/trace/beauty/mmap.c, tools/perf/util/event.c and tools/perf/util/map.c depend on several macros in mman.h, which are lost on old systems like ubuntu 12.04. They are architecture

Not "lost on old systems", changing that to "not present on old systems"

Quoted 6 lines

dependened macros. Importing ./arch/*/include/uapi/asm/mman.h into tools/ is not easy because mman.h for some unusual archs (like tile) have extra dependencies.

This patch introduces only required macros into mman-fix.h. Macros list is gotten from tools/perf/trace/beauty/mmap.c.

ok, I'll try keeping the include/uapi/asm-generic/mman.h and arch/alpha/include/uapi/asm/mman.h with just what you added, so that at least the .c files appears as using the headers were those things are defined in the kernel sources.

Ah, and good eyes in realizing this is not the same value for all arches!

- Arnaldo

Quoted 562 lines

This patch is gnerated using following bash script:

#!/bin/bash

function begin_mman_fix_header()

 {
   echo "#ifndef $1" >  $2
   echo "#define $1" >> $2
   echo "#include <sys/mman.h>" >> $2

}

function finish_mman_fix_header()
{
echo "#endif // $1" >> $2
echo "Finish writing $2"
}

function build_mman_fix_header()
{
guard=$1
shift
target=$1
shift
begin_mman_fix_header $guard $target
for src in $@
do
if [ -f $src ]
then
for macro in $macros
do
if grep '#define[ \t]*'$macro $src > /dev/null 2>&1
then
echo "#ifndef $macro" >> $target
grep '#define[ \t]*'$macro $src | sed 's/[ \t]*\/\*.*$//g' >> $target echo "#endif" >> $target
fi
done
fi
done
}

macros=grep ifndef tools/perf/trace/beauty/mmap.c | awk '{print $2}'

baseheader=tools/include/uapi/asm-generic/mman-fix.h
build_mman_fix_header __TOOLS_UAPI_ASM_MMAN_FIX_H $baseheader include/uapi/asm-generic/mman* echo "#ifndef MAP_UNINITIALIZED" >> $baseheader
echo "#define MAP_UNINITIALIZED 0x4000000" >> $baseheader
echo "#endif" >> $baseheader
finish_mman_fix_header __TOOLS_UAPI_ASM_MMAN_FIX_H $baseheader

archs=ls tools/arch
for arch in $archs
do
archheader=tools/arch/$arch/include/uapi/asm/mman-fix.h
if [ ! -d tools/arch/$arch/include/uapi/asm ]
then
mkdir -p tools/arch/$arch/include/uapi/asm
fi
uppercase=echo $arch | awk '{print toupper($0)}'
build_mman_fix_header TOOLS_ARCH_${uppercase}_UAPI_ASM_MMAN_FIX_H $archheader arch/$arch/include/uapi/asm/mman.h echo "#include <asm-generic/mman-fix.h>" >> $archheader
finish_mman_fix_header TOOLS_ARCH_${uppercase}_UAPI_ASM_MMAN_FIX_H $archheader
done

Cc Nilay Vaish <[email protected]>
Cc Hou Pengyang <[email protected]>
Cc He Kuang <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/arch/alpha/include/uapi/asm/mman-fix.h      | 38 +++++++++++++++++++
 tools/arch/arm/include/uapi/asm/mman-fix.h        |  5 +++
 tools/arch/arm64/include/uapi/asm/mman-fix.h      |  5 +++
 tools/arch/frv/include/uapi/asm/mman-fix.h        |  5 +++
 tools/arch/h8300/include/uapi/asm/mman-fix.h      |  5 +++
 tools/arch/hexagon/include/uapi/asm/mman-fix.h    |  5 +++
 tools/arch/ia64/include/uapi/asm/mman-fix.h       |  5 +++
 tools/arch/m32r/include/uapi/asm/mman-fix.h       |  5 +++
 tools/arch/microblaze/include/uapi/asm/mman-fix.h |  5 +++
 tools/arch/mips/include/uapi/asm/mman-fix.h       | 41 ++++++++++++++++++++
 tools/arch/mn10300/include/uapi/asm/mman-fix.h    |  5 +++
 tools/arch/parisc/include/uapi/asm/mman-fix.h     | 38 +++++++++++++++++++
 tools/arch/powerpc/include/uapi/asm/mman-fix.h    | 11 ++++++
 tools/arch/s390/include/uapi/asm/mman-fix.h       |  5 +++
 tools/arch/score/include/uapi/asm/mman-fix.h      |  5 +++
 tools/arch/sh/include/uapi/asm/mman-fix.h         |  5 +++
 tools/arch/sparc/include/uapi/asm/mman-fix.h      | 11 ++++++
 tools/arch/tile/include/uapi/asm/mman-fix.h       | 11 ++++++
 tools/arch/x86/include/uapi/asm/mman-fix.h        |  8 ++++
 tools/arch/xtensa/include/uapi/asm/mman-fix.h     | 38 +++++++++++++++++++
 tools/include/uapi/asm-generic/mman-fix.h         | 46 +++++++++++++++++++++++
 tools/perf/MANIFEST                               |  2 +
 22 files changed, 304 insertions(+)
 create mode 100644 tools/arch/alpha/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/arm/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/arm64/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/frv/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/h8300/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/hexagon/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/ia64/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/m32r/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/microblaze/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/mips/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/mn10300/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/parisc/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/powerpc/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/s390/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/score/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/sh/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/sparc/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/tile/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/x86/include/uapi/asm/mman-fix.h
 create mode 100644 tools/arch/xtensa/include/uapi/asm/mman-fix.h
 create mode 100644 tools/include/uapi/asm-generic/mman-fix.h
tools/arch/alpha/include/uapi/asm/mman-fix.h new file +38 -0
new file mode 100644
index 0000000..f807a71
@@ -0,0 +1,38 @@
+#ifndef TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x8
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x100
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x10
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x80000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x100000
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
tools/arch/arm/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..a29dae1
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
tools/arch/arm64/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..e50c0d1
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
tools/arch/frv/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..8c2eb44
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
tools/arch/h8300/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..e639fe6
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
tools/arch/hexagon/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..dda9359
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
tools/arch/ia64/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..1e98f36
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
tools/arch/m32r/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..74aa94d
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
tools/arch/microblaze/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..90b7a53
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
tools/arch/mips/include/uapi/asm/mman-fix.h new file +41 -0
new file mode 100644
index 0000000..ef58cd7
@@ -0,0 +1,41 @@
+#ifndef TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x10
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x010
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x0800
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x40000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x80000
+#endif
+#ifndef MADV_HWPOISON
+#define MADV_HWPOISON	 100
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE	 12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE 15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP	16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H
tools/arch/mn10300/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..86a2903
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
tools/arch/parisc/include/uapi/asm/mman-fix.h new file +38 -0
new file mode 100644
index 0000000..c157a03
@@ -0,0 +1,38 @@
+#ifndef TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x8
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x04
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x10
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x40000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x80000
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   65
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 66
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	67
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	68
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   69
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	70
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
tools/arch/powerpc/include/uapi/asm/mman-fix.h new file +11 -0
new file mode 100644
index 0000000..4b552fa
@@ -0,0 +1,11 @@
+#ifndef TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_STACK
+#define MAP_STACK	0x20000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x40000
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
tools/arch/s390/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..d7755dd
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
tools/arch/score/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..97ad192
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
tools/arch/sh/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..d17bca8
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
tools/arch/sparc/include/uapi/asm/mman-fix.h new file +11 -0
new file mode 100644
index 0000000..3ac4ba0
@@ -0,0 +1,11 @@
+#ifndef TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_STACK
+#define MAP_STACK	0x20000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x40000
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
tools/arch/tile/include/uapi/asm/mman-fix.h new file +11 -0
new file mode 100644
index 0000000..105a3b0e
@@ -0,0 +1,11 @@
+#ifndef TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_STACK
+#define MAP_STACK	MAP_GROWSDOWN
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x4000
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
tools/arch/x86/include/uapi/asm/mman-fix.h new file +8 -0
new file mode 100644
index 0000000..0cda2bf
@@ -0,0 +1,8 @@
+#ifndef TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_32BIT
+#define MAP_32BIT	0x40
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
tools/arch/xtensa/include/uapi/asm/mman-fix.h new file +38 -0
new file mode 100644
index 0000000..9ec9051
@@ -0,0 +1,38 @@
+#ifndef TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x10
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x010
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x0800
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x40000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x80000
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
tools/include/uapi/asm-generic/mman-fix.h new file +46 -0
new file mode 100644
index 0000000..f47eb4c
@@ -0,0 +1,46 @@
+#ifndef __TOOLS_UAPI_ASM_MMAN_FIX_H
+#define __TOOLS_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x8
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x10
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x20
+#endif
+#ifndef MADV_HWPOISON
+#define MADV_HWPOISON	100
+#endif
+#ifndef MADV_SOFT_OFFLINE
+#define MADV_SOFT_OFFLINE 101
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x20000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x40000
+#endif
+#ifndef MAP_UNINITIALIZED
+#define MAP_UNINITIALIZED 0x4000000
+#endif
+#endif // __TOOLS_UAPI_ASM_MMAN_FIX_H
tools/perf/MANIFEST +2 -0
index ff200c6..56ac24f 100644
@@ -66,6 +66,7 @@ tools/include/linux/hash.h
 tools/include/linux/kernel.h
 tools/include/linux/list.h
 tools/include/linux/log2.h
+tools/include/uapi/asm-generic/mman-fix.h
 tools/include/uapi/linux/bpf.h
 tools/include/uapi/linux/bpf_common.h
 tools/include/uapi/linux/hw_breakpoint.h
@@ -80,3 +81,4 @@ tools/include/linux/err.h
 tools/include/linux/bitmap.h
 tools/include/linux/time64.h
 tools/arch/*/include/uapi/asm/perf_regs.h
+tools/arch/*/include/uapi/asm/mman-fix.h
Signature · 1 line
1.8.3.4
#3 lore raw

Re: [PATCH 1/2] perf tools: Introduce memory mapping macros in mman-fix.h

Quoted 11 lines · Arnaldo Carvalho de Melo

Em Tue, Sep 06, 2016 at 05:48:51AM +0000, Wang Nan escreveu:

Quoted 3 lines

tools/perf/trace/beauty/mmap.c, tools/perf/util/event.c and tools/perf/util/map.c depend on several macros in mman.h, which are lost on old systems like ubuntu 12.04. They are architecture

Not "lost on old systems", changing that to "not present on old systems"

Quoted 5 lines

dependened macros. Importing ./arch/*/include/uapi/asm/mman.h into tools/ is not easy because mman.h for some unusual archs (like tile) have extra dependencies.
This patch introduces only required macros into mman-fix.h. Macros list is gotten from tools/perf/trace/beauty/mmap.c.

Quoted 7 lines

ok, I'll try keeping the include/uapi/asm-generic/mman.h and arch/alpha/include/uapi/asm/mman.h with just what you added, so that at least the .c files appears as using the headers were those things are defined in the kernel sources.

Ah, and good eyes in realizing this is not the same value for all arches!

This is why we have to define these macros for each archs. Your solution in tools/perf/trace/beauty/mmap.c works for x86 only.

However, I don't like this patchset because we add 300+ lines of code and 22 new files for less than 15 macros, and only one of them I really concern. Moreover, futhre code require more symbols in uapi and we have to add new headers, finally we will clone the whole uapi. We have to stop doing this...

For the hugetlb problem, I think you can take the v2 patch without this 2 patches:

http://lkml.kernel.org/r/[email protected]

so old system can compile without hugetlb support.

This is the reason why I separated into 2 patch series.

Thank you.

Quoted 564 lines

- Arnaldo

Quoted 562 lines

This patch is gnerated using following bash script:

#!/bin/bash

  function begin_mman_fix_header()
  {
    echo "#ifndef $1" >  $2
    echo "#define $1" >> $2
    echo "#include <sys/mman.h>" >> $2
  }

  function finish_mman_fix_header()
  {
    echo "#endif // $1" >> $2
    echo "Finish writing $2"
  }

  function build_mman_fix_header()
  {
    guard=$1
    shift
    target=$1
    shift
    begin_mman_fix_header $guard $target
    for src in $@
    do
      if [ -f $src ]
      then
        for macro in $macros
        do
          if grep '#define[ \t]*'$macro $src > /dev/null 2>&1
          then
            echo "#ifndef $macro" >> $target
            grep '#define[ \t]*'$macro $src | sed 's/[ \t]*\/\*.*$//g' >> $target
            echo "#endif" >> $target
          fi
        done
      fi
    done
  }

macros=grep ifndef tools/perf/trace/beauty/mmap.c | awk '{print $2}'

baseheader=tools/include/uapi/asm-generic/mman-fix.h
build_mman_fix_header __TOOLS_UAPI_ASM_MMAN_FIX_H $baseheader include/uapi/asm-generic/mman* echo "#ifndef MAP_UNINITIALIZED" >> $baseheader
echo "#define MAP_UNINITIALIZED 0x4000000" >> $baseheader
echo "#endif" >> $baseheader
finish_mman_fix_header __TOOLS_UAPI_ASM_MMAN_FIX_H $baseheader

  archs=`ls tools/arch`
  for arch in $archs
  do
    archheader=tools/arch/$arch/include/uapi/asm/mman-fix.h
    if [ ! -d tools/arch/$arch/include/uapi/asm ]
    then
      mkdir -p tools/arch/$arch/include/uapi/asm
    fi
    uppercase=`echo $arch | awk '{print toupper($0)}'`
    build_mman_fix_header TOOLS_ARCH_${uppercase}_UAPI_ASM_MMAN_FIX_H $archheader arch/$arch/include/uapi/asm/mman.h
    echo "#include <asm-generic/mman-fix.h>" >> $archheader
    finish_mman_fix_header TOOLS_ARCH_${uppercase}_UAPI_ASM_MMAN_FIX_H $archheader
  done
Cc Nilay Vaish <[email protected]>
Cc Hou Pengyang <[email protected]>
Cc He Kuang <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
  tools/arch/alpha/include/uapi/asm/mman-fix.h      | 38 +++++++++++++++++++
  tools/arch/arm/include/uapi/asm/mman-fix.h        |  5 +++
  tools/arch/arm64/include/uapi/asm/mman-fix.h      |  5 +++
  tools/arch/frv/include/uapi/asm/mman-fix.h        |  5 +++
  tools/arch/h8300/include/uapi/asm/mman-fix.h      |  5 +++
  tools/arch/hexagon/include/uapi/asm/mman-fix.h    |  5 +++
  tools/arch/ia64/include/uapi/asm/mman-fix.h       |  5 +++
  tools/arch/m32r/include/uapi/asm/mman-fix.h       |  5 +++
  tools/arch/microblaze/include/uapi/asm/mman-fix.h |  5 +++
  tools/arch/mips/include/uapi/asm/mman-fix.h       | 41 ++++++++++++++++++++
  tools/arch/mn10300/include/uapi/asm/mman-fix.h    |  5 +++
  tools/arch/parisc/include/uapi/asm/mman-fix.h     | 38 +++++++++++++++++++
  tools/arch/powerpc/include/uapi/asm/mman-fix.h    | 11 ++++++
  tools/arch/s390/include/uapi/asm/mman-fix.h       |  5 +++
  tools/arch/score/include/uapi/asm/mman-fix.h      |  5 +++
  tools/arch/sh/include/uapi/asm/mman-fix.h         |  5 +++
  tools/arch/sparc/include/uapi/asm/mman-fix.h      | 11 ++++++
  tools/arch/tile/include/uapi/asm/mman-fix.h       | 11 ++++++
  tools/arch/x86/include/uapi/asm/mman-fix.h        |  8 ++++
  tools/arch/xtensa/include/uapi/asm/mman-fix.h     | 38 +++++++++++++++++++
  tools/include/uapi/asm-generic/mman-fix.h         | 46 +++++++++++++++++++++++
  tools/perf/MANIFEST                               |  2 +
  22 files changed, 304 insertions(+)

create mode 100644 tools/arch/alpha/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/arm/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/arm64/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/frv/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/h8300/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/hexagon/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/ia64/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/m32r/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/microblaze/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/mips/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/mn10300/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/parisc/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/powerpc/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/s390/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/score/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/sh/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/sparc/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/tile/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/x86/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/xtensa/include/uapi/asm/mman-fix.h create mode 100644 tools/include/uapi/asm-generic/mman-fix.h

tools/arch/alpha/include/uapi/asm/mman-fix.h new file +38 -0
new file mode 100644
index 0000000..f807a71
@@ -0,0 +1,38 @@
+#ifndef TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x8
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x100
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x10
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x80000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x100000
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
tools/arch/arm/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..a29dae1
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
tools/arch/arm64/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..e50c0d1
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
tools/arch/frv/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..8c2eb44
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
tools/arch/h8300/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..e639fe6
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
tools/arch/hexagon/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..dda9359
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
tools/arch/ia64/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..1e98f36
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
tools/arch/m32r/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..74aa94d
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
tools/arch/microblaze/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..90b7a53
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
tools/arch/mips/include/uapi/asm/mman-fix.h new file +41 -0
new file mode 100644
index 0000000..ef58cd7
@@ -0,0 +1,41 @@
+#ifndef TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x10
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x010
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x0800
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x40000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x80000
+#endif
+#ifndef MADV_HWPOISON
+#define MADV_HWPOISON	 100
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE	 12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE 15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP	16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H
tools/arch/mn10300/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..86a2903
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
tools/arch/parisc/include/uapi/asm/mman-fix.h new file +38 -0
new file mode 100644
index 0000000..c157a03
@@ -0,0 +1,38 @@
+#ifndef TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x8
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x04
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x10
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x40000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x80000
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   65
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 66
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	67
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	68
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   69
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	70
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
tools/arch/powerpc/include/uapi/asm/mman-fix.h new file +11 -0
new file mode 100644
index 0000000..4b552fa
@@ -0,0 +1,11 @@
+#ifndef TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_STACK
+#define MAP_STACK	0x20000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x40000
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
tools/arch/s390/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..d7755dd
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
tools/arch/score/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..97ad192
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
tools/arch/sh/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..d17bca8
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
tools/arch/sparc/include/uapi/asm/mman-fix.h new file +11 -0
new file mode 100644
index 0000000..3ac4ba0
@@ -0,0 +1,11 @@
+#ifndef TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_STACK
+#define MAP_STACK	0x20000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x40000
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
tools/arch/tile/include/uapi/asm/mman-fix.h new file +11 -0
new file mode 100644
index 0000000..105a3b0e
@@ -0,0 +1,11 @@
+#ifndef TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_STACK
+#define MAP_STACK	MAP_GROWSDOWN
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x4000
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
tools/arch/x86/include/uapi/asm/mman-fix.h new file +8 -0
new file mode 100644
index 0000000..0cda2bf
@@ -0,0 +1,8 @@
+#ifndef TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_32BIT
+#define MAP_32BIT	0x40
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
tools/arch/xtensa/include/uapi/asm/mman-fix.h new file +38 -0
new file mode 100644
index 0000000..9ec9051
@@ -0,0 +1,38 @@
+#ifndef TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x10
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x010
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x0800
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x40000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x80000
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
tools/include/uapi/asm-generic/mman-fix.h new file +46 -0
new file mode 100644
index 0000000..f47eb4c
@@ -0,0 +1,46 @@
+#ifndef __TOOLS_UAPI_ASM_MMAN_FIX_H
+#define __TOOLS_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x8
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x10
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x20
+#endif
+#ifndef MADV_HWPOISON
+#define MADV_HWPOISON	100
+#endif
+#ifndef MADV_SOFT_OFFLINE
+#define MADV_SOFT_OFFLINE 101
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x20000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x40000
+#endif
+#ifndef MAP_UNINITIALIZED
+#define MAP_UNINITIALIZED 0x4000000
+#endif
+#endif // __TOOLS_UAPI_ASM_MMAN_FIX_H
tools/perf/MANIFEST +2 -0
index ff200c6..56ac24f 100644
@@ -66,6 +66,7 @@ tools/include/linux/hash.h
  tools/include/linux/kernel.h
  tools/include/linux/list.h
  tools/include/linux/log2.h
+tools/include/uapi/asm-generic/mman-fix.h
  tools/include/uapi/linux/bpf.h
  tools/include/uapi/linux/bpf_common.h
  tools/include/uapi/linux/hw_breakpoint.h
@@ -80,3 +81,4 @@ tools/include/linux/err.h
  tools/include/linux/bitmap.h
  tools/include/linux/time64.h
  tools/arch/*/include/uapi/asm/perf_regs.h
+tools/arch/*/include/uapi/asm/mman-fix.h
Signature · 1 line
1.8.3.4
#4 lore raw

Re: [PATCH 1/2] perf tools: Introduce memory mapping macros in mman-fix.h

Em Tue, Sep 06, 2016 at 09:25:47PM +0800, Wangnan (F) escreveu:

Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 11 lines

Em Tue, Sep 06, 2016 at 05:48:51AM +0000, Wang Nan escreveu:

Quoted 3 lines

tools/perf/trace/beauty/mmap.c, tools/perf/util/event.c and tools/perf/util/map.c depend on several macros in mman.h, which are lost on old systems like ubuntu 12.04. They are architecture

Not "lost on old systems", changing that to "not present on old systems"

Quoted 5 lines

dependened macros. Importing ./arch/*/include/uapi/asm/mman.h into tools/ is not easy because mman.h for some unusual archs (like tile) have extra dependencies.
This patch introduces only required macros into mman-fix.h. Macros list is gotten from tools/perf/trace/beauty/mmap.c.

Quoted 7 lines

ok, I'll try keeping the include/uapi/asm-generic/mman.h and arch/alpha/include/uapi/asm/mman.h with just what you added, so that at least the .c files appears as using the headers were those things are defined in the kernel sources.

Ah, and good eyes in realizing this is not the same value for all arches!

This is why we have to define these macros for each archs. Your solution in tools/perf/trace/beauty/mmap.c works for x86 only.

Quoted 6 lines

However, I don't like this patchset because we add 300+ lines of code and 22 new files for less than 15 macros, and only one of them I really concern. Moreover, futhre code require more symbols in uapi and we have to add new headers, finally we will clone the whole uapi. We have to stop doing this...

Why? If we want to support older newer kernels running on older distros, which is a valid goal, or recent tool source code on older distros, where fallbacks will take place with their older kernels, and if we have the build automated for that (I have) then why not keep the tools building on as many different userspaces as possible?

I'm not even putting this as a burden to you, that may choose to support only recent systems, but since I have this automated and can catch such problems, I intend to keep the tool building in as many systems as possible.

The good thing about my report was that you noticed a problem in existing code, i.e. the 'perf trace' beautifier that was working only on x86, thanks for that!

Quoted 6 lines

For the hugetlb problem, I think you can take the v2 patch without this 2 patches:

http://lkml.kernel.org/r/[email protected]

so old system can compile without hugetlb support.

Right, I understood your intention, to have both independent.

Quoted 3 lines

This is the reason why I separated into 2 patch series.

Thank you.

thanks,

- Arnaldo

Quoted 564 lines
Quoted 563 lines

- Arnaldo

Quoted 562 lines

This patch is gnerated using following bash script:

#!/bin/bash

  function begin_mman_fix_header()
  {
    echo "#ifndef $1" >  $2
    echo "#define $1" >> $2
    echo "#include <sys/mman.h>" >> $2
  }

  function finish_mman_fix_header()
  {
    echo "#endif // $1" >> $2
    echo "Finish writing $2"
  }

  function build_mman_fix_header()
  {
    guard=$1
    shift
    target=$1
    shift
    begin_mman_fix_header $guard $target
    for src in $@
    do
      if [ -f $src ]
      then
        for macro in $macros
        do
          if grep '#define[ \t]*'$macro $src > /dev/null 2>&1
          then
            echo "#ifndef $macro" >> $target
            grep '#define[ \t]*'$macro $src | sed 's/[ \t]*\/\*.*$//g' >> $target
            echo "#endif" >> $target
          fi
        done
      fi
    done
  }

macros=grep ifndef tools/perf/trace/beauty/mmap.c | awk '{print $2}'

baseheader=tools/include/uapi/asm-generic/mman-fix.h
build_mman_fix_header __TOOLS_UAPI_ASM_MMAN_FIX_H $baseheader include/uapi/asm-generic/mman* echo "#ifndef MAP_UNINITIALIZED" >> $baseheader
echo "#define MAP_UNINITIALIZED 0x4000000" >> $baseheader
echo "#endif" >> $baseheader
finish_mman_fix_header __TOOLS_UAPI_ASM_MMAN_FIX_H $baseheader

  archs=`ls tools/arch`
  for arch in $archs
  do
    archheader=tools/arch/$arch/include/uapi/asm/mman-fix.h
    if [ ! -d tools/arch/$arch/include/uapi/asm ]
    then
      mkdir -p tools/arch/$arch/include/uapi/asm
    fi
    uppercase=`echo $arch | awk '{print toupper($0)}'`
    build_mman_fix_header TOOLS_ARCH_${uppercase}_UAPI_ASM_MMAN_FIX_H $archheader arch/$arch/include/uapi/asm/mman.h
    echo "#include <asm-generic/mman-fix.h>" >> $archheader
    finish_mman_fix_header TOOLS_ARCH_${uppercase}_UAPI_ASM_MMAN_FIX_H $archheader
  done
Cc Nilay Vaish <[email protected]>
Cc Hou Pengyang <[email protected]>
Cc He Kuang <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
  tools/arch/alpha/include/uapi/asm/mman-fix.h      | 38 +++++++++++++++++++
  tools/arch/arm/include/uapi/asm/mman-fix.h        |  5 +++
  tools/arch/arm64/include/uapi/asm/mman-fix.h      |  5 +++
  tools/arch/frv/include/uapi/asm/mman-fix.h        |  5 +++
  tools/arch/h8300/include/uapi/asm/mman-fix.h      |  5 +++
  tools/arch/hexagon/include/uapi/asm/mman-fix.h    |  5 +++
  tools/arch/ia64/include/uapi/asm/mman-fix.h       |  5 +++
  tools/arch/m32r/include/uapi/asm/mman-fix.h       |  5 +++
  tools/arch/microblaze/include/uapi/asm/mman-fix.h |  5 +++
  tools/arch/mips/include/uapi/asm/mman-fix.h       | 41 ++++++++++++++++++++
  tools/arch/mn10300/include/uapi/asm/mman-fix.h    |  5 +++
  tools/arch/parisc/include/uapi/asm/mman-fix.h     | 38 +++++++++++++++++++
  tools/arch/powerpc/include/uapi/asm/mman-fix.h    | 11 ++++++
  tools/arch/s390/include/uapi/asm/mman-fix.h       |  5 +++
  tools/arch/score/include/uapi/asm/mman-fix.h      |  5 +++
  tools/arch/sh/include/uapi/asm/mman-fix.h         |  5 +++
  tools/arch/sparc/include/uapi/asm/mman-fix.h      | 11 ++++++
  tools/arch/tile/include/uapi/asm/mman-fix.h       | 11 ++++++
  tools/arch/x86/include/uapi/asm/mman-fix.h        |  8 ++++
  tools/arch/xtensa/include/uapi/asm/mman-fix.h     | 38 +++++++++++++++++++
  tools/include/uapi/asm-generic/mman-fix.h         | 46 +++++++++++++++++++++++
  tools/perf/MANIFEST                               |  2 +
  22 files changed, 304 insertions(+)

create mode 100644 tools/arch/alpha/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/arm/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/arm64/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/frv/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/h8300/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/hexagon/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/ia64/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/m32r/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/microblaze/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/mips/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/mn10300/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/parisc/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/powerpc/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/s390/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/score/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/sh/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/sparc/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/tile/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/x86/include/uapi/asm/mman-fix.h create mode 100644 tools/arch/xtensa/include/uapi/asm/mman-fix.h create mode 100644 tools/include/uapi/asm-generic/mman-fix.h

tools/arch/alpha/include/uapi/asm/mman-fix.h new file +38 -0
new file mode 100644
index 0000000..f807a71
@@ -0,0 +1,38 @@
+#ifndef TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x8
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x100
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x10
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x80000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x100000
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
tools/arch/arm/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..a29dae1
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
tools/arch/arm64/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..e50c0d1
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
tools/arch/frv/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..8c2eb44
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
tools/arch/h8300/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..e639fe6
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
tools/arch/hexagon/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..dda9359
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
tools/arch/ia64/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..1e98f36
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
tools/arch/m32r/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..74aa94d
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
tools/arch/microblaze/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..90b7a53
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
tools/arch/mips/include/uapi/asm/mman-fix.h new file +41 -0
new file mode 100644
index 0000000..ef58cd7
@@ -0,0 +1,41 @@
+#ifndef TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x10
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x010
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x0800
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x40000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x80000
+#endif
+#ifndef MADV_HWPOISON
+#define MADV_HWPOISON	 100
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE	 12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE 15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP	16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H
tools/arch/mn10300/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..86a2903
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
tools/arch/parisc/include/uapi/asm/mman-fix.h new file +38 -0
new file mode 100644
index 0000000..c157a03
@@ -0,0 +1,38 @@
+#ifndef TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x8
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x04
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x10
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x40000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x80000
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   65
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 66
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	67
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	68
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   69
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	70
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
tools/arch/powerpc/include/uapi/asm/mman-fix.h new file +11 -0
new file mode 100644
index 0000000..4b552fa
@@ -0,0 +1,11 @@
+#ifndef TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_STACK
+#define MAP_STACK	0x20000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x40000
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
tools/arch/s390/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..d7755dd
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
tools/arch/score/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..97ad192
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
tools/arch/sh/include/uapi/asm/mman-fix.h new file +5 -0
new file mode 100644
index 0000000..d17bca8
@@ -0,0 +1,5 @@
+#ifndef TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
tools/arch/sparc/include/uapi/asm/mman-fix.h new file +11 -0
new file mode 100644
index 0000000..3ac4ba0
@@ -0,0 +1,11 @@
+#ifndef TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_STACK
+#define MAP_STACK	0x20000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x40000
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
tools/arch/tile/include/uapi/asm/mman-fix.h new file +11 -0
new file mode 100644
index 0000000..105a3b0e
@@ -0,0 +1,11 @@
+#ifndef TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_STACK
+#define MAP_STACK	MAP_GROWSDOWN
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x4000
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
tools/arch/x86/include/uapi/asm/mman-fix.h new file +8 -0
new file mode 100644
index 0000000..0cda2bf
@@ -0,0 +1,8 @@
+#ifndef TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef MAP_32BIT
+#define MAP_32BIT	0x40
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
tools/arch/xtensa/include/uapi/asm/mman-fix.h new file +38 -0
new file mode 100644
index 0000000..9ec9051
@@ -0,0 +1,38 @@
+#ifndef TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
+#define TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x10
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x010
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x0800
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x40000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x80000
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#include <asm-generic/mman-fix.h>
+#endif // TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
tools/include/uapi/asm-generic/mman-fix.h new file +46 -0
new file mode 100644
index 0000000..f47eb4c
@@ -0,0 +1,46 @@
+#ifndef __TOOLS_UAPI_ASM_MMAN_FIX_H
+#define __TOOLS_UAPI_ASM_MMAN_FIX_H
+#include <sys/mman.h>
+#ifndef PROT_SEM
+#define PROT_SEM	0x8
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED	0x10
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS	0x20
+#endif
+#ifndef MADV_HWPOISON
+#define MADV_HWPOISON	100
+#endif
+#ifndef MADV_SOFT_OFFLINE
+#define MADV_SOFT_OFFLINE 101
+#endif
+#ifndef MADV_MERGEABLE
+#define MADV_MERGEABLE   12
+#endif
+#ifndef MADV_UNMERGEABLE
+#define MADV_UNMERGEABLE 13
+#endif
+#ifndef MADV_HUGEPAGE
+#define MADV_HUGEPAGE	14
+#endif
+#ifndef MADV_NOHUGEPAGE
+#define MADV_NOHUGEPAGE	15
+#endif
+#ifndef MADV_DONTDUMP
+#define MADV_DONTDUMP   16
+#endif
+#ifndef MADV_DODUMP
+#define MADV_DODUMP	17
+#endif
+#ifndef MAP_STACK
+#define MAP_STACK	0x20000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB	0x40000
+#endif
+#ifndef MAP_UNINITIALIZED
+#define MAP_UNINITIALIZED 0x4000000
+#endif
+#endif // __TOOLS_UAPI_ASM_MMAN_FIX_H
tools/perf/MANIFEST +2 -0
index ff200c6..56ac24f 100644
@@ -66,6 +66,7 @@ tools/include/linux/hash.h
  tools/include/linux/kernel.h
  tools/include/linux/list.h
  tools/include/linux/log2.h
+tools/include/uapi/asm-generic/mman-fix.h
  tools/include/uapi/linux/bpf.h
  tools/include/uapi/linux/bpf_common.h
  tools/include/uapi/linux/hw_breakpoint.h
@@ -80,3 +81,4 @@ tools/include/linux/err.h
  tools/include/linux/bitmap.h
  tools/include/linux/time64.h
  tools/arch/*/include/uapi/asm/perf_regs.h
+tools/arch/*/include/uapi/asm/mman-fix.h
Signature · 1 line
1.8.3.4
#5 lore raw

Re: [PATCH 1/2] perf tools: Introduce memory mapping macros in mman-fix.h

Quoted 31 lines · Arnaldo Carvalho de Melo

Em Tue, Sep 06, 2016 at 09:25:47PM +0800, Wangnan (F) escreveu:

Quoted 24 lines · Arnaldo Carvalho de Melo
Quoted 11 lines

Em Tue, Sep 06, 2016 at 05:48:51AM +0000, Wang Nan escreveu:

Quoted 3 lines

tools/perf/trace/beauty/mmap.c, tools/perf/util/event.c and tools/perf/util/map.c depend on several macros in mman.h, which are lost on old systems like ubuntu 12.04. They are architecture

Not "lost on old systems", changing that to "not present on old systems"

Quoted 5 lines

dependened macros. Importing ./arch/*/include/uapi/asm/mman.h into tools/ is not easy because mman.h for some unusual archs (like tile) have extra dependencies.
This patch introduces only required macros into mman-fix.h. Macros list is gotten from tools/perf/trace/beauty/mmap.c.

Quoted 7 lines

ok, I'll try keeping the include/uapi/asm-generic/mman.h and arch/alpha/include/uapi/asm/mman.h with just what you added, so that at least the .c files appears as using the headers were those things are defined in the kernel sources.

Ah, and good eyes in realizing this is not the same value for all arches!

This is why we have to define these macros for each archs. Your solution in tools/perf/trace/beauty/mmap.c works for x86 only.

Quoted 6 lines

However, I don't like this patchset because we add 300+ lines of code and 22 new files for less than 15 macros, and only one of them I really concern. Moreover, futhre code require more symbols in uapi and we have to add new headers, finally we will clone the whole uapi. We have to stop doing this...

Quoted 5 lines

Why? If we want to support older newer kernels running on older distros, which is a valid goal, or recent tool source code on older distros, where fallbacks will take place with their older kernels, and if we have the build automated for that (I have) then why not keep the tools building on as many different userspaces as possible?

Your automated building checker is great. I mean we have to find a way to stop pulling kernel headers to tools/include.

But since we haven't find such a way, I'll continously improve this mman.h stuff. As your suggestion, I'll try to put them in uapi/mman.h, not mman-fix.h. This require a building check for each arch.

Thank you.

#6 lore raw

Re: [PATCH 1/2] perf tools: Introduce memory mapping macros in mman-fix.h

Em Tue, Sep 06, 2016 at 11:28:35PM +0800, Wangnan (F) escreveu:

Quoted 32 lines · Arnaldo Carvalho de Melo
Quoted 31 lines

Em Tue, Sep 06, 2016 at 09:25:47PM +0800, Wangnan (F) escreveu:

Quoted 30 lines · Arnaldo Carvalho de Melo
Quoted 11 lines

Em Tue, Sep 06, 2016 at 05:48:51AM +0000, Wang Nan escreveu:

Quoted 3 lines

tools/perf/trace/beauty/mmap.c, tools/perf/util/event.c and tools/perf/util/map.c depend on several macros in mman.h, which are lost on old systems like ubuntu 12.04. They are architecture

Not "lost on old systems", changing that to "not present on old systems"

Quoted 5 lines

dependened macros. Importing ./arch/*/include/uapi/asm/mman.h into tools/ is not easy because mman.h for some unusual archs (like tile) have extra dependencies.
This patch introduces only required macros into mman-fix.h. Macros list is gotten from tools/perf/trace/beauty/mmap.c.

Quoted 7 lines

ok, I'll try keeping the include/uapi/asm-generic/mman.h and arch/alpha/include/uapi/asm/mman.h with just what you added, so that at least the .c files appears as using the headers were those things are defined in the kernel sources.

Ah, and good eyes in realizing this is not the same value for all arches!

This is why we have to define these macros for each archs. Your solution in tools/perf/trace/beauty/mmap.c works for x86 only.

However, I don't like this patchset because we add 300+ lines of code and 22 new files for less than 15 macros, and only one of them I really concern. Moreover, futhre code require more symbols in uapi and we have to add new headers, finally we will clone the whole uapi. We have to stop doing this...

Quoted 8 lines
Quoted 5 lines

Why? If we want to support older newer kernels running on older distros, which is a valid goal, or recent tool source code on older distros, where fallbacks will take place with their older kernels, and if we have the build automated for that (I have) then why not keep the tools building on as many different userspaces as possible?

Your automated building checker is great. I mean we have to find a way to stop pulling kernel headers to tools/include.

Well, if we want the source code to build on older systems, then we must provide #defines for things not present in such older systems, we would have to put it somewhere, so why not to put it in the same header as the kernel puts?

Quoted 2 lines

But since we haven't find such a way, I'll continously improve this mman.h stuff.

We could, for instance, use the kernel headers, then, building perf on older systems would not be a problem, the kernel sources goes with the perf tool sources, they are in the same repository.

But this requires that the kernel developers make sure the perf tool builds, which was deemed a burden to them. Thus the copy.

Quoted 1 line

As your suggestion, I'll try to put them in uapi/mman.h, not

Thanks!

Quoted 1 line

mman-fix.h. This require a building check for each arch.

Well, for the things that are strict copies, yes, having those diff based checks would help us to figure out new files in the kernel for which we have copies, but that isn't so _strictly_ needed for cases where we avoided some of the dependencies in the kernel headers by copying just what we need in tools/.

- Arnaldo

author
#7 lore raw

PATCH 2/2 perf tools: Fix mman macros using mman-fix.h

In reply to Wang Nan

Use mman-fix.h to fix potential undefined macros in mman.h for building perf in old systems.

Cc Nilay Vaish <[email protected]>
Cc Hou Pengyang <[email protected]>
Cc He Kuang <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/trace/beauty/mmap.c | 63 +-----------------------------------------
 tools/perf/util/event.c        |  5 +---
 tools/perf/util/map.c          |  3 +-
 3 files changed, 3 insertions(+), 68 deletions(-)
tools/perf/trace/beauty/mmap.c +1 -62
index d0a3a8e..c96b3e2 100644
@@ -1,8 +1,5 @@
 #include <sys/mman.h>
-
-#ifndef PROT_SEM
-#define PROT_SEM 0x8
-#endif
+#include <asm/mman-fix.h>
 
 static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size,
 					       struct syscall_arg *arg)
@@ -33,31 +30,6 @@ static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size,
 
 #define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot
 
-#ifndef MAP_FIXED
-#define MAP_FIXED		     0x10
-#endif
-
-#ifndef MAP_ANONYMOUS
-#define MAP_ANONYMOUS		     0x20
-#endif
-
-#ifndef MAP_32BIT
-#define MAP_32BIT		     0x40
-#endif
-
-#ifndef MAP_STACK
-#define MAP_STACK		  0x20000
-#endif
-
-#ifndef MAP_HUGETLB
-#define MAP_HUGETLB		  0x40000
-#endif
-
-#ifndef MAP_UNINITIALIZED
-#define MAP_UNINITIALIZED	0x4000000
-#endif
-
-
 static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size,
 						struct syscall_arg *arg)
 {
@@ -125,39 +97,6 @@ static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size,
 
 #define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags
 
-#ifndef MADV_HWPOISON
-#define MADV_HWPOISON		100
-#endif
-
-#ifndef MADV_SOFT_OFFLINE
-#define MADV_SOFT_OFFLINE	101
-#endif
-
-#ifndef MADV_MERGEABLE
-#define MADV_MERGEABLE		 12
-#endif
-
-#ifndef MADV_UNMERGEABLE
-#define MADV_UNMERGEABLE	 13
-#endif
-
-#ifndef MADV_HUGEPAGE
-#define MADV_HUGEPAGE		 14
-#endif
-
-#ifndef MADV_NOHUGEPAGE
-#define MADV_NOHUGEPAGE		 15
-#endif
-
-#ifndef MADV_DONTDUMP
-#define MADV_DONTDUMP		 16
-#endif
-
-#ifndef MADV_DODUMP
-#define MADV_DODUMP		 17
-#endif
-
-
 static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size,
 						      struct syscall_arg *arg)
 {
tools/perf/util/event.c +1 -4
index 23c3ebd..df85931 100644
@@ -1,5 +1,6 @@
 #include <linux/types.h>
 #include <sys/mman.h>
+#include <asm/mman-fix.h>
 #include <api/fs/fs.h>
 #include "event.h"
 #include "debug.h"
@@ -249,10 +250,8 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
 	bool truncation = false;
 	unsigned long long timeout = proc_map_timeout * 1000000ULL;
 	int rc = 0;
-#ifdef MAP_HUGETLB
 	const char *hugetlbfs_mnt = hugetlbfs__mountpoint();
 	int hugetlbfs_mnt_len = hugetlbfs_mnt ? strlen(hugetlbfs_mnt) : 0;
-#endif
 
 	if (machine__is_default_guest(machine))
 		return 0;
@@ -347,12 +346,10 @@ out:
 
 		if (!strcmp(execname, ""))
 			strcpy(execname, anonstr);
-#ifdef MAP_HUGETLB
 		if (!strncmp(execname, hugetlbfs_mnt, hugetlbfs_mnt_len)) {
 			strcpy(execname, anonstr);
 			event->mmap2.flags |= MAP_HUGETLB;
 		}
-#endif
 
 		size = strlen(execname) + 1;
 		memcpy(event->mmap2.filename, execname, size);
tools/perf/util/map.c +1 -2
index f52d460..76c68853 100644
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <asm/mman-fix.h>
 #include "map.h"
 #include "thread.h"
 #include "strlist.h"
@@ -29,9 +30,7 @@ static inline int is_anon_memory(const char *filename, u32 flags)
 {
 	u32 anon_flags = 0;
 
-#ifdef MAP_HUGETLB
 	anon_flags |= MAP_HUGETLB;
-#endif
 	return flags & anon_flags ||
 	       !strcmp(filename, "//anon") ||
 	       !strncmp(filename, "/dev/zero", sizeof("/dev/zero") - 1) ||
Signature · 1 line
1.8.3.4