Skip to content

Commit

Permalink
numactl/libnuma: version 1 source code compatibility
Browse files Browse the repository at this point in the history
Andi suggested we supply some compatibility wrappers with a compat
define for old programs.

This patch provides numacompat1.h and additions to numa.h, which provide
source code compatibility to libnuma version 1.
(The application progamming interface changes, but the ABI is preserved
 through the use of symbol versioning.  So the library stays libnuma.so.1)

numa.h includes numacompat1.h if VERSION1_COMPATIBILITY is defined.

Makefile is changed to install numacompat1.h

The libnuma.c change fixes a bug in numa_node_to_cpus_v2() and adds a
bitmask-to-bitmask copy for unequal-size masks.

The numa.3 man page documents the bitmask copies and the source code
compatibility.

I've tested the source code compatibility by using the version 1
programs in the test suite.

I plan to include this patch (when I get your feedback) and post the
current source as numactl-2.0.0-rc1.tar.gz on
http://oss.sgi.com/projects/libnuma/

Signed-off-by: Cliff Wickman <cpw@sgi.com>
  • Loading branch information
cpwickman authored and filbranden committed Jul 23, 2014
1 parent 49b051a commit 14cba69
Show file tree
Hide file tree
Showing 7 changed files with 411 additions and 20 deletions.
33 changes: 33 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,36 @@ updating in newer kernels (Mel Gorman)
- Fix parallel Makefile build (Andreas Herrmann)
- Fix target command argument parsing for numactl (no -- needed again anymore)
- Clarify numa_node_to_cpus() manpage

2.0.0[-rc1]

- Version 2 (symbol versioning)
- Modify libnuma to use variable-length bit masks (the bitmask structure)
- Modify numactl, migspeed, memhog, migratepages, numademo and stream_main
to use variable-length bit masks
- Modify the test/ programs to use the libnuma that uses variable size bit masks
- Man page changes with the change to variable-length bit masks, move_pages
migrate_pages and others
- Add the migspeed test program to test the speed of migrating pages from
one node to another
- Support for move_pages(2) to numactl, and numa_move_pages() to libnuma
- Add the move_pages test command to exercise the move_pages(2) system call
- Add the mbind_mig_pages test command to verify the moving of a task's
pages with move_pages(2)
- Add the migrate_pages test command to test that a task's pages can be
moved with move_pages(2)
- Support numactl +nn syntax for cpuset_relative cpu and node numbers
- L.S. :
- libnuma man pages -- General Cleanup
- add numa_get_mems_allowed()
- fix checktopology regression test
- numa_maps man page clarifications and cleanup
- minor cleanups of numademo.c
- numactl - fix numastat sysfs scanning
- numactl - reorganize regress test script.
- fix mempolicy regression test for assymetric platforms and memoryless nodes.
- numactl - fix checkaffinity regression test
- numactl - fix/cleanup libnuma local allocation behavior
- P.M. :
- fix __NR_migrate_pages reference.
- Provide numacompat1.h for source code compatibility with version 1
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# these can (and should) be overridden on the make command line for production
# use
CFLAGS := -g -Wall -O2
# these are used for the benchmarks in addition to the normal CFLAGS.
# Normally no need to overwrite unless you find a new magic flag to make
Expand Down Expand Up @@ -117,7 +116,7 @@ tonodemask_memory distance

MANPAGES := numa.3 numactl.8 numastat.8 migratepages.8 migspeed.8

install: numactl migratepages migspeed numademo.c numamon memhog libnuma.so.1 numa.h numaif.h numastat ${MANPAGES}
install: numactl migratepages migspeed numademo.c numamon memhog libnuma.so.1 numa.h numaif.h numacompat1.h numastat ${MANPAGES}
mkdir -p ${prefix}/bin
cp numactl ${prefix}/bin
cp migratepages ${prefix}/bin
Expand All @@ -133,7 +132,7 @@ install: numactl migratepages migspeed numademo.c numamon memhog libnuma.so.1 nu
cp libnuma.so.1 ${libdir}
cd ${libdir} ; ln -sf libnuma.so.1 libnuma.so
mkdir -p ${prefix}/include
cp numa.h numaif.h ${prefix}/include
cp numa.h numaif.h numacompat1.h ${prefix}/include
cp numastat ${prefix}/bin
if [ -d ${docdir} ] ; then \
mkdir -p ${docdir}/numactl/examples ; \
Expand Down
25 changes: 24 additions & 1 deletion libnuma.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct bitmask *numa_allocate_nodemask(void);
void set_sizes(void);
void copy_nodemask_to_bitmask(nodemask_t *, struct bitmask *);
void copy_bitmask_to_nodemask(struct bitmask *, nodemask_t *);
void copy_bitmask_to_bitmask(struct bitmask *, struct bitmask *);

static inline void
nodemask_set_v1(nodemask_t *mask, int node)
Expand Down Expand Up @@ -983,6 +984,28 @@ copy_bitmask_to_nodemask(struct bitmask *bmp, nodemask_t *nmp)
}
}

/*
* copy a bitmask map body to another bitmask body
* fill a larger destination with zeroes
*/
void
copy_bitmask_to_bitmask(struct bitmask *bmpfrom, struct bitmask *bmpto)
{
int bytes;

if (bmpfrom->size >= bmpto->size) {
memcpy(bmpto->maskp, bmpfrom->maskp, CPU_BYTES(bmpto->size));
} else if (bmpfrom->size < bmpto->size) {
bytes = CPU_BYTES(bmpfrom->size);
memcpy(bmpto->maskp, bmpfrom->maskp, bytes);
memset(((char *)bmpto->maskp)+bytes, 0,
CPU_BYTES(bmpto->size)-bytes);
} else {
bytes = CPU_BYTES(bmpfrom->size);
memcpy(bmpto->maskp, bmpfrom->maskp, bytes);
}
}

/*
* copy a numa.h nodemask_t structure to a bitmask map body
*/
Expand Down Expand Up @@ -1262,7 +1285,7 @@ numa_node_to_cpus_v2(int node, struct bitmask *buffer)
}

free(line);
memcpy(buffer->maskp, mask->maskp, bufferlen);
copy_bitmask_to_bitmask(mask, buffer);

/* slightly racy, see above */
/* save the mask we created */
Expand Down
43 changes: 42 additions & 1 deletion numa.3
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ numa \- NUMA policy library
.BI "struct bitmask *numa_bitmask_setall(struct bitmask *" bmp );
.br
.BI "struct bitmask *numa_bitmask_setbit(struct bitmask *" bmp ", unsigned int " n );
.br
.BI "void copy_bitmask_to_nodemask(struct bitmask *" bmp ", nodemask_t *" nodemask )
.br
.BI "void copy_nodemask_to_bitmask(nodemask_t *" nodemask ", struct bitmask *" bmp )
.br
.BI "void copy_bitmask_to_bitmask(struct bitmask *" bmpfrom ", struct bitmask *" bmpto )
.sp
.BI "int numa_move_pages(int " pid ", unsigned long " count ", void **" pages ", const int *" nodes ", int *" status ", int " flags );
.br
Expand Down Expand Up @@ -802,6 +808,33 @@ returned). The value of
.I bmp
is always returned.

.BR copy_bitmask_to_nodemask()
copies the body (the bit map itself) of the bitmask structure pointed
to by
.I bmp
to the nodemask_t structure pointed to by the
.I nodemask
pointer. If the two areas differ in size, the copy is truncated to the size
of the receiving field or zero-filled.

.BR copy_nodemask_to_bitmask()
copies the nodemask_t structure pointed to by the
.I nodemask
pointer to the body (the bit map itself) of the bitmask structure pointed
to by the
.I bmp
pointer. If the two areas differ in size, the copy is truncated to the size
of the receiving field or zero-filled.

.BR copy_bitmask_to_bitmask()
copies the body (the bit map itself) of the bitmask structure pointed
to by the
.I bmpfrom
pointer to the body of the bitmask structure pointed to by the
.I bmpto
pointer. If the two areas differ in size, the copy is truncated to the size
of the receiving field or zero-filled.

.br
.BR numa_move_pages()
moves a list of pages in the address space of the currently
Expand Down Expand Up @@ -893,14 +926,22 @@ number identifying each warning. After that there is a
.BR printf (3)-style
format string and a variable number of arguments.

.SH Compatibility with libnuma version 1
Binaries that were compiled for libnuma version 1 need not be re-compiled
to run with libnuma version 2.
.br
Source codes written for libnuma version 1 may be re-compiled without
change with version 2 installed. To do so, in the code's Makefile add
this option to CFLAGS: -DVERSION1_COMPATIBILITY

.SH THREAD SAFETY
.I numa_set_bind_policy
and
.I numa_exit_on_error
are process global. The other calls are thread safe.

.SH COPYRIGHT
Copyright 2002, 2004, 2007, Andi Kleen, SuSE Labs.
Copyright 2002, 2004, 2007, 2008 Andi Kleen, SuSE Labs.
.I libnuma
is under the GNU Lesser General Public License, v2.1.

Expand Down
Loading

0 comments on commit 14cba69

Please sign in to comment.