summaryrefslogtreecommitdiffstats
path: root/vespabase/src/start-cbinaries.sh
blob: 91ce8edede478c55322e0a3cd88585c4a3f2fd56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/sh
# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

# BEGIN environment bootstrap section
# Do not edit between here and END as this section should stay identical in all scripts

findpath () {
    myname=${0}
    mypath=${myname%/*}
    myname=${myname##*/}
    if [ "$mypath" ] && [ -d "$mypath" ]; then
        return
    fi
    mypath=$(pwd)
    if [ -f "${mypath}/${myname}" ]; then
        return
    fi
    echo "FATAL: Could not figure out the path where $myname lives from $0"
    exit 1
}

COMMON_ENV=libexec/vespa/common-env.sh

source_common_env () {
    if [ "$VESPA_HOME" ] && [ -d "$VESPA_HOME" ]; then
        # ensure it ends with "/" :
        VESPA_HOME=${VESPA_HOME%/}/
        export VESPA_HOME
        common_env=$VESPA_HOME/$COMMON_ENV
        if [ -f "$common_env" ]; then
            . $common_env
            return
        fi
    fi
    return 1
}

findroot () {
    source_common_env && return
    if [ "$VESPA_HOME" ]; then
        echo "FATAL: bad VESPA_HOME value '$VESPA_HOME'"
        exit 1
    fi
    if [ "$ROOT" ] && [ -d "$ROOT" ]; then
        VESPA_HOME="$ROOT"
        source_common_env && return
    fi
    findpath
    while [ "$mypath" ]; do
        VESPA_HOME=${mypath}
        source_common_env && return
        mypath=${mypath%/*}
    done
    echo "FATAL: missing VESPA_HOME environment variable"
    echo "Could not locate $COMMON_ENV anywhere"
    exit 1
}

findroot

# END environment bootstrap section

bname=`basename $0`
no_valgrind=true
use_callgrind=false

case $VESPA_VALGRIND_OPT in
    *callgrind*) use_callgrind=true;;
esac

for f in $VESPA_USE_VALGRIND
do
    # log_debug_message "Testing '$f'"
    if [ "$f" = "$bname" ]; then
        # log_debug_message "I ($bname) shall use valgrind, as set in VESPA_USE_VALGRIND"
        no_valgrind=false
        break
    fi
done

if [ "$VESPA_USE_VALGRIND" = "all" ]; then
    # log_debug_message "I shall use valgrind, as VESPA_USE_VALGRIND is 'all'"
    no_valgrind=false
fi

# special malloc setup; we should make some better mechanism for this
#
export GLIBCXX_FORCE_NEW=1
#
unset LD_PRELOAD
p64=/home/y/lib64
p32=/home/y/lib32
pre=/home/y/lib
suf=vespa/malloc/libvespamalloc.so
#
# should really check that format is same as binary below
#
for f in $VESPA_USE_HUGEPAGES_LIST
do
    # log_debug_message "Testing '$f'"
    if [ "$f" = "$bname" ]; then
        # log_debug_message "I ($bname) shall use huge pages, as set in VESPA_USE_HUGEPAGES_LIST"
        export VESPA_USE_HUGEPAGES="yes"
        break
    fi
done

if [ "$VESPA_USE_HUGEPAGES_LIST" = "all" ]; then
    # log_debug_message "I shall use huge pages, as VESPA_USE_HUGEPAGES_LIST is 'all'"
    export VESPA_USE_HUGEPAGES="yes"
fi

for f in $VESPA_USE_MADVISE_LIST
do
    # log_debug_message "Testing '$f'"
    app=`echo $f | cut -d '=' -f1`
    limit=`echo $f | cut -d '=' -f2`
    if [ "$app" = "$bname" ]; then
        log_debug_message "I ($bname) shall use madvise with limit $limit, as set in VESPA_USE_MADVISE_LIST"
        export VESPA_MALLOC_MADVISE_LIMIT="$limit"
        break
    fi

    if [ "$app" = "all" ]; then
        log_debug_message "I shall use madvise with limit $limit, as VESPA_USE_MADVISE_LIST is 'all'"
        export VESPA_MALLOC_MADVISE_LIMIT="$limit"
    fi
done

for f in $VESPA_USE_NO_VESPAMALLOC
do
    # log_debug_message "Testing '$f'"
    if [ "$f" = "$bname" ]; then
        # log_debug_message "I ($bname) shall not use vespamalloc, as set in VESPA_USE_NO_VESPAMALLOC"
        suf=vespa/malloc/libvespamalloc_notexisting.so
        break
    fi
done

if [ "$VESPA_USE_NO_VESPAMALLOC" = "all" ]; then
    # log_debug_message "I shall not use, as VESPA_USE_NO_VESPAMALLOC is 'all'"
    suf=vespa/malloc/libvespamalloc_notexisting.so
fi

for f in $VESPA_USE_VESPAMALLOC
do
    # log_debug_message "Testing '$f'"
    if [ "$f" = "$bname" ]; then
        # log_debug_message "I ($bname) shall use libvespamalloc, as set in VESPA_USE_VESPAMALLOC"
        suf=vespa/malloc/libvespamalloc.so
        break
    fi
done

if [ "$VESPA_USE_VESPAMALLOC" = "all" ]; then
    # log_debug_message "I shall use libvespamalloc, as VESPA_USE_VESPAMALLOC is 'all'"
    suf=vespa/malloc/libvespamalloc.so
fi

for f in $VESPA_USE_VESPAMALLOC_D
do
    # log_debug_message "Testing '$f'"
    if [ "$f" = "$bname" ]; then
        # log_debug_message "I ($bname) shall use libvespamallocd, as set in VESPA_USE_VESPAMALLOC_D"
        suf=vespa/malloc/libvespamallocd.so
        break
    fi
done

if [ "$VESPA_USE_VESPAMALLOC_D" = "all" ]; then
    # log_debug_message "I shall use libvespamallocd, as VESPA_USE_VESPAMALLOC_D is 'all'"
    suf=vespa/malloc/libvespamallocd.so
fi

for f in $VESPA_USE_VESPAMALLOC_DST
do
    # log_debug_message "Testing '$f'"
    if [ "$f" = "$bname" ]; then
        # log_debug_message "I ($bname) shall use libvespamallocdst16, as set in VESPA_USE_VESPAMALLOC_DST"
        suf=vespa/malloc/libvespamallocdst16.so
        break
    fi
done

if [ "$VESPA_USE_VESPAMALLOC_DST" = "all" ]; then
    # log_debug_message "I shall use libvespamallocdst16, as VESPA_USE_VESPAMALLOC_DST is 'all'"
    suf=vespa/malloc/libvespamallocdst16.so
fi

if [[ ($no_valgrind || $use_callgrind) && -z $VESPA_RUN_STANDALONE ]]; then
    for tryfile in $p64/$suf $p32/$suf $pre/$suf ; do
        if [ -f $tryfile ]; then
                LD_PRELOAD=$tryfile
		log_debug_message "Using LD_PRELOAD=$tryfile"
                if [ "$VESPA_USE_HUGEPAGES" ]; then
                    export VESPA_MALLOC_HUGEPAGES="$VESPA_USE_HUGEPAGES"
		    log_debug_message "enabling hugepages for '$0-bin'."
                fi
                break
        fi
    done
fi

# log_debug_message "VESPA_USE_VALGRIND='$VESPA_USE_VALGRIND'; bname='$bname'; no_valgrind='$no_valgrind'"

if $no_valgrind || ! which valgrind >/dev/null ; then
    # log_debug_message $0-bin $@
    if [ -z $VESPA_RUN_STANDALONE ]; then
        ulimit -c unlimited
    fi
    if numactl --interleave all true &> /dev/null; then
        # We are allowed to use numactl
        if [ "$VESPA_AFFINITY_CPU_SOCKET" ]; then
            numcpu=`numactl --hardware | grep available | cut -d' ' -f2`
            node=$(($VESPA_AFFINITY_CPU_SOCKET % $numcpu))
            log_debug_message "Starting $0 with affinity on cpu $VESPA_AFFINITY_CPU_SOCKET out of $numcpu : " \
                 numactl --cpunodebind=$node --membind=$node env LD_PRELOAD=$LD_PRELOAD $0-bin "$@"
            exec numactl --cpunodebind=$node --membind=$node env LD_PRELOAD=$LD_PRELOAD $0-bin "$@"
        else
            log_debug_message "Starting $0 with memory interleaving on all nodes : " \
                 numactl --interleave all env LD_PRELOAD=$LD_PRELOAD $0-bin "$@"
            exec numactl --interleave all env LD_PRELOAD=$LD_PRELOAD $0-bin "$@"
        fi
    else
        log_debug_message "Starting $0 without numactl (no permission or not available) : " \
             env LD_PRELOAD=$LD_PRELOAD $0-bin "$@"
        exec env LD_PRELOAD=$LD_PRELOAD $0-bin "$@"
    fi
else
    if $use_callgrind ; then
        export LD_PRELOAD
    else
        export LD_PRELOAD=""
    fi
    # ignore signal until shared libraries have loaded, etc:
    trap "" SIGTERM
    log_debug_message "Starting : " \
         valgrind $VESPA_VALGRIND_OPT --log-file=/home/y/tmp/valgrind.$bname.log.$$ $0-bin "$@"
    exec valgrind $VESPA_VALGRIND_OPT --log-file=/home/y/tmp/valgrind.$bname.log.$$ $0-bin "$@"
fi