Skip to content

Commit b173291

Browse files
committed
issue: 1557652 Introduce compiler.m4
Use no optimization for asm functions Signed-off-by: Igor Ivanov <[email protected]>
1 parent cfcc6b8 commit b173291

File tree

5 files changed

+103
-19
lines changed

5 files changed

+103
-19
lines changed

config/m4/compiler.m4

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# compiler.m4 - Parsing compiler capabilities
2+
#
3+
# Copyright (C) Mellanox Technologies Ltd. 2001-2018. ALL RIGHTS RESERVED.
4+
# See file LICENSE for terms.
5+
#
6+
7+
8+
# Check compiler specific attributes
9+
# Usage: CHECK_COMPILER_ATTRIBUTE([attribute], [program], [definition])
10+
# Note:
11+
# - [definition] can be omitted if it is equal to attribute
12+
#
13+
AC_DEFUN([CHECK_COMPILER_ATTRIBUTE], [
14+
AC_CACHE_VAL(vma_cv_attribute_[$1], [
15+
#
16+
# Try to compile using the C compiler
17+
#
18+
AC_TRY_COMPILE([$2],[],
19+
[vma_cv_attribute_$1=yes],
20+
[vma_cv_attribute_$1=no])
21+
AS_IF([test "x$vma_cv_attribute_$1" = "xyes"], [
22+
AC_LANG_PUSH(C++)
23+
AC_TRY_COMPILE([extern "C" {
24+
$2
25+
}],[],
26+
[vma_cv_attribute_$1=yes],
27+
[vma_cv_attribute_$1=no])
28+
AC_LANG_POP(C++)
29+
])
30+
])
31+
32+
AC_MSG_CHECKING([for attribute $1])
33+
AC_MSG_RESULT([$vma_cv_attribute_$1])
34+
AS_IF([test "x$vma_cv_attribute_$1" = "xyes"], [
35+
AS_IF([test "x$3" = "x"],
36+
[AC_DEFINE_UNQUOTED([DEFINED_$1], [1], [Define to 1 if attribute $1 is supported])],
37+
[AC_DEFINE_UNQUOTED([DEFINED_$3], [1], [Define to 1 if attribute $1 is supported])]
38+
)
39+
])
40+
])
41+
42+
43+
44+
##########################
45+
# Set compiler capabilities
46+
#
47+
AC_DEFUN([COMPILER_CAPABILITY_SETUP],
48+
[
49+
50+
CHECK_COMPILER_ATTRIBUTE([optimize],
51+
[int foo (int arg) __attribute__ ((optimize("O0")));],
52+
[ATTRIBUTE_OPTIMIZE])
53+
])

configure.ac

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ m4_include([config/m4/opt.m4])
8888
m4_include([config/m4/verbs.m4])
8989
m4_include([config/m4/nl.m4])
9090
m4_include([config/m4/prof.m4])
91+
m4_include([config/m4/compiler.m4])
9192

9293
FUNC_CONFIGURE_INIT()
9394

@@ -163,6 +164,7 @@ case $CC in
163164
;;
164165
esac
165166

167+
COMPILER_CAPABILITY_SETUP()
166168

167169
dnl===-----------------------------------------------------------------------===
168170
dnl===
@@ -387,22 +389,6 @@ dnl===
387389
dnl===-----------------------------------------------------------------------===
388390
show_section_title "Check for functions, types and structures"
389391

390-
# Does this compiler have built-in functions for atomic memory access?
391-
AC_MSG_CHECKING([for atomic memory access (__sync_bool_compare_and_swap) support])
392-
AC_TRY_LINK(,
393-
[
394-
int variable = 1;
395-
return (__sync_bool_compare_and_swap(&variable, 1, 2)
396-
&& __sync_add_and_fetch(&variable, 1)) ? 1 : 0;
397-
],
398-
[
399-
AC_MSG_RESULT([yes])
400-
AC_DEFINE(HAVE_BUILTIN_ATOMIC, 1, [Define to 1 if gcc supports __sync_bool_compare_and_swap() a.o.])
401-
],
402-
[
403-
AC_MSG_RESULT([no])
404-
])
405-
406392
AC_MSG_CHECKING([for SOF_TIMESTAMPING_SOFTWARE support])
407393
AC_TRY_LINK(
408394
#include <linux/net_tstamp.h>

src/utils/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ libutils_la_SOURCES = \
1313
clock.h \
1414
lock_wrapper.h \
1515
rdtsc.h \
16-
types.h
16+
types.h \
17+
compiler.h
1718

1819
noinst_PROGRAMS = timetest
1920
timetest_LDADD = -lrt libutils.la

src/utils/compiler.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2001-2018 Mellanox Technologies, Ltd. All rights reserved.
3+
*
4+
* This software is available to you under a choice of one of two
5+
* licenses. You may choose to be licensed under the terms of the GNU
6+
* General Public License (GPL) Version 2, available from the file
7+
* COPYING in the main directory of this source tree, or the
8+
* BSD license below:
9+
*
10+
* Redistribution and use in source and binary forms, with or
11+
* without modification, are permitted provided that the following
12+
* conditions are met:
13+
*
14+
* - Redistributions of source code must retain the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer.
17+
*
18+
* - Redistributions in binary form must reproduce the above
19+
* copyright notice, this list of conditions and the following
20+
* disclaimer in the documentation and/or other materials
21+
* provided with the distribution.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
31+
*/
32+
33+
34+
#ifndef SRC_UTILS_COMPILER_H_
35+
#define SRC_UTILS_COMPILER_H_
36+
37+
#if defined(DEFINED_ATTRIBUTE_OPTIMIZE)
38+
#define VMA_ATTRIBUTE_OPTIMIZE_NONE __attribute__((optimize("O0")))
39+
#else
40+
#define VMA_ATTRIBUTE_OPTIMIZE_NONE
41+
#endif
42+
43+
#endif /* SRC_UTILS_COMPILER_H_ */

src/vma/util/sys_vars.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "vtypes.h"
4343
#include "config.h"
4444

45+
#include "utils/compiler.h"
4546
#include "vma/ib/base/verbs_extra.h"
4647
#include "vma/util/sysctl_reader.h"
4748
#include "vma/vma_extra.h"
@@ -428,8 +429,8 @@ struct mce_sys_var {
428429
int env_to_cpuset(char *orig_start, cpu_set_t *cpu_set);
429430
void read_env_variable_with_pid(char* mce_sys_name, size_t mce_sys_max_size, char* env_ptr);
430431
bool check_cpuinfo_flag(const char* flag);
431-
bool cpuid_hv();
432-
const char* cpuid_hv_vendor();
432+
bool cpuid_hv() VMA_ATTRIBUTE_OPTIMIZE_NONE;
433+
const char* cpuid_hv_vendor() VMA_ATTRIBUTE_OPTIMIZE_NONE;
433434
void read_hv();
434435

435436
// prevent unautothrized creation of objects

0 commit comments

Comments
 (0)