forked from atheme/libmowgli-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
include ../../../extra.mk | ||
|
||
STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_PLATFORM} | ||
STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_PLATFORM} | ||
|
||
SUBDIRS = win32 | ||
|
||
INCLUDES = constructor.h machine.h | ||
SRCS = cacheline.c | ||
|
||
INCLUDES = cacheline.h constructor.h machine.h | ||
|
||
include ../../../buildsys.mk | ||
|
||
includesubdir = $(PACKAGE_NAME)/platform | ||
|
||
include ../../../extra.mk | ||
CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* libmowgli: A collection of useful routines for programming. | ||
* cacheline.c: Platform specific routines to get L1 cache line size | ||
* | ||
* Copyright (c) 2013 Patrick McFarland <[email protected]> | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice is present in all copies. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "mowgli.h" | ||
|
||
size_t _mowgli_cacheline_size; | ||
|
||
void mowgli_cacheline_init(void) { | ||
#ifdef MOWGLI_OS_LINUX | ||
_mowgli_cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); | ||
#elif MOWGLI_OS_OSX | ||
sysctlbyname("hw.cachelinesize", &_mowgli_cacheline_size, | ||
sizeof(size_t), 0, 0); | ||
#elif MOWGLI_OS_WIN | ||
#define SLPI SYSTEM_LOGICAL_PROCESSOR_INFORMATION | ||
DWORD buf_size = 0; | ||
DWORD i = 0; | ||
SLPI *buf = 0; | ||
|
||
GetLogicalProcessorInformation(0, &buf_size); | ||
buf = (SLPI *)atheme_alloc(buf_size); | ||
GetLogicalProcessorInformation(&buf[0], &buf_size); | ||
|
||
for (i = 0; i != buf_size / sizeof(SLPI); ++i) { | ||
if (buf[i].Relationship == RelationCache && buf[i].Cache.Level == 1) { | ||
_mowgli_cacheline_size = buf[i].Cache.LineSize; | ||
break; | ||
} | ||
} | ||
|
||
atheme_free(buffer); | ||
#undef SLPI | ||
#else | ||
// This is often true | ||
#ifdef MOWGLI_CPU_BITS_32 | ||
_mowgli_cacheline_size = 32; | ||
#else | ||
_mowgli_cacheline_size = 64; | ||
#endif | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* libmowgli: A collection of useful routines for programming. | ||
* cacheline.h: Platform specific routines to get L1 cache line size | ||
* | ||
* Copyright (c) 2013 Patrick McFarland <[email protected]> | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice is present in all copies. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
extern size_t _mowgli_cacheline_size; | ||
|
||
static inline size_t mowgli_cacheline_size(void) { | ||
return _mowgli_cacheline_size; | ||
} |