From: Nathan Scott Date: Mon, 9 Aug 2004 05:41:55 +0000 (+0000) Subject: Fix up auto-detection of available libc features being used by xfs_io; including... X-Git-Tag: v2.7.0~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0bba1a493312ce0038fafa4d142057647f8f93c4;p=thirdparty%2Fxfsprogs-dev.git Fix up auto-detection of available libc features being used by xfs_io; including sendfile, fadvise, madvise, etc. --- diff --git a/aclocal.m4 b/aclocal.m4 index c274667b5..1eb6831e9 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -232,6 +232,142 @@ AC_DEFUN([AC_PACKAGE_NEED_PTHREADMUTEXINIT], AC_SUBST(libpthread) ]) +# +# Check if we have a working fadvise system call +# +AC_DEFUN([AC_HAVE_FADVISE], + [ AC_MSG_CHECKING([for fadvise ]) + AC_TRY_COMPILE([ +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include + ], [ + posix_fadvise(0, 1, 0, 0); + ], have_fadvise=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_fadvise) + ]) + +# +# Check if we have a working madvise system call +# +AC_DEFUN([AC_HAVE_MADVISE], + [ AC_MSG_CHECKING([for madvise ]) + AC_TRY_COMPILE([ +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include + ], [ + posix_madvise(0, 0, MADV_NORMAL); + ], have_madvise=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_madvise) + ]) + +# +# Check if we have a working mincore system call +# +AC_DEFUN([AC_HAVE_MINCORE], + [ AC_MSG_CHECKING([for mincore ]) + AC_TRY_COMPILE([ +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include + ], [ + mincore(0, 0, 0); + ], have_mincore=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_mincore) + ]) + +# +# Check if we have a working sendfile system call +# +AC_DEFUN([AC_HAVE_SENDFILE], + [ AC_MSG_CHECKING([for sendfile ]) + AC_TRY_COMPILE([ +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include + ], [ + sendfile(0, 0, 0, 0); + ], have_sendfile=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_sendfile) + ]) + +# +# Check if we have a working fadvise system call +# +AC_DEFUN([AC_HAVE_FADVISE], + [ AC_MSG_CHECKING([for fadvise ]) + AC_TRY_COMPILE([ +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include + ], [ + posix_fadvise(0, 1, 0, 0); + ], have_fadvise=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_fadvise) + ]) + +# +# Check if we have a working madvise system call +# +AC_DEFUN([AC_HAVE_MADVISE], + [ AC_MSG_CHECKING([for madvise ]) + AC_TRY_COMPILE([ +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include + ], [ + posix_madvise(0, 0, MADV_NORMAL); + ], have_madvise=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_madvise) + ]) + +# +# Check if we have a working mincore system call +# +AC_DEFUN([AC_HAVE_MINCORE], + [ AC_MSG_CHECKING([for mincore ]) + AC_TRY_COMPILE([ +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include + ], [ + mincore(0, 0, 0); + ], have_mincore=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_mincore) + ]) + +# +# Check if we have a working sendfile system call +# +AC_DEFUN([AC_HAVE_SENDFILE], + [ AC_MSG_CHECKING([for sendfile ]) + AC_TRY_COMPILE([ +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include + ], [ + sendfile(0, 0, 0, 0); + ], have_sendfile=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_sendfile) + ]) + # # Check if we have a type for the pointer's size integer (__psint_t) # diff --git a/configure.in b/configure.in index d12087bd3..c3a2a4a2e 100644 --- a/configure.in +++ b/configure.in @@ -34,6 +34,11 @@ AC_PACKAGE_NEED_UUIDCOMPARE AC_PACKAGE_NEED_PTHREAD_H AC_PACKAGE_NEED_PTHREADMUTEXINIT +AC_HAVE_FADVISE +AC_HAVE_MADVISE +AC_HAVE_MINCORE +AC_HAVE_SENDFILE + AC_TYPE_PSINT AC_TYPE_PSUNSIGNED AC_SIZEOF_POINTERS_AND_LONG diff --git a/include/builddefs.in b/include/builddefs.in index 6ff453a42..7710215aa 100644 --- a/include/builddefs.in +++ b/include/builddefs.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved. +# Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of version 2 of the GNU General Public License as @@ -94,6 +94,11 @@ ENABLE_EDITLINE = @enable_editline@ ENABLE_READLINE = @enable_readline@ HAVE_ZIPPED_MANPAGES = @have_zipped_manpages@ +HAVE_FADVISE = @have_fadvise@ +HAVE_MADVISE = @have_madvise@ +HAVE_MINCORE = @have_mincore@ +HAVE_SENDFILE = @have_sendfile@ + ifeq ($(PKG_PLATFORM),linux) PCFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 endif diff --git a/io/Makefile b/io/Makefile index da5d69eab..6a39d5c9c 100644 --- a/io/Makefile +++ b/io/Makefile @@ -41,11 +41,32 @@ CFILES = command.c input.c init.c \ mmap.c open.c pread.c prealloc.c pwrite.c quit.c \ truncate.c -ifeq ($(PKG_PLATFORM),linux) -CFILES += fadvise.c sendfile.c -LCFLAGS += -DHAVE_FADVISE -DHAVE_SENDFILE +ifeq ($(HAVE_FADVISE),yes) +CFILES += fadvise.c +LCFLAGS += -DHAVE_FADVISE else -LSRCFILES += fadvise.c sendfile.c +LSRCFILES += fadvise.c +endif + +ifeq ($(HAVE_MADVISE),yes) +CFILES += madvise.c +LCFLAGS += -DHAVE_MADVISE +else +LSRCFILES += madvise.c +endif + +ifeq ($(HAVE_MINCORE),yes) +CFILES += mincore.c +LCFLAGS += -DHAVE_MINCORE +else +LSRCFILES += mincore.c +endif + +ifeq ($(HAVE_SENDFILE),yes) +CFILES += sendfile.c +LCFLAGS += -DHAVE_SENDFILE +else +LSRCFILES += sendfile.c endif ifneq ($(PKG_PLATFORM),irix) diff --git a/io/command.c b/io/command.c index 9370d5583..041ad76f6 100644 --- a/io/command.c +++ b/io/command.c @@ -123,25 +123,3 @@ find_command( } return NULL; } - -void -init_commands(void) -{ - bmap_init(); - fadvise_init(); - file_init(); - freeze_init(); - fsync_init(); - help_init(); - inject_init(); - mmap_init(); - open_init(); - pread_init(); - prealloc_init(); - pwrite_init(); - quit_init(); - resblks_init(); - sendfile_init(); - shutdown_init(); - truncate_init(); -} diff --git a/io/command.h b/io/command.h index 4f331560a..fb3377a79 100644 --- a/io/command.h +++ b/io/command.h @@ -59,48 +59,4 @@ extern void add_command(const cmdinfo_t *ci); extern int command_usage(const cmdinfo_t *ci); extern int command(int argc, char **argv); extern const cmdinfo_t *find_command(const char *cmd); -extern void init_commands(void); -extern void bmap_init(void); -extern void file_init(void); -extern void freeze_init(void); -extern void fsync_init(void); -extern void help_init(void); -extern void inject_init(void); -extern void mmap_init(void); -extern void open_init(void); -extern void pread_init(void); -extern void prealloc_init(void); -extern void pwrite_init(void); -extern void quit_init(void); -extern void truncate_init(void); - -#ifdef HAVE_FADVISE -extern void fadvise_init(void); -#else -#define fadvise_init() do { } while (0) -#endif - -#ifdef HAVE_INJECT -extern void inject_init(void); -#else -#define inject_init() do { } while (0) -#endif - -#ifdef HAVE_RESBLKS -extern void resblks_init(void); -#else -#define resblks_init() do { } while (0) -#endif - -#ifdef HAVE_SENDFILE -extern void sendfile_init(void); -#else -#define sendfile_init() do { } while (0) -#endif - -#ifdef HAVE_SHUTDOWN -extern void shutdown_init(void); -#else -#define shutdown_init() do { } while (0) -#endif diff --git a/io/fadvise.c b/io/fadvise.c index 04508148e..29dede4b8 100644 --- a/io/fadvise.c +++ b/io/fadvise.c @@ -38,26 +38,6 @@ static cmdinfo_t fadvise_cmd; -#if !defined(__NR_fadvise64) -# if defined(__i386__) -# define __NR_fadvise64 250 -# elif defined(__ia64__) -# define __NR_fadvise64 1234 -# elif defined(__powerpc__) -# define __NR_fadvise64 233 -# endif -#endif - -static int -fadvise64(int fd, off64_t offset, size_t len, int advise) -{ -#ifdef __NR_fadvise64 - return syscall(__NR_fadvise64, fd, offset, len, advise); -#else - errno = ENOSYS; return -1; -#endif -} - static void fadvise_help(void) { @@ -139,7 +119,7 @@ fadvise_f( return command_usage(&fadvise_cmd); } - if (fadvise64(file->fd, offset, length, advise) < 0) { + if (posix_fadvise64(file->fd, offset, length, advise) < 0) { perror("fadvise"); return 0; } diff --git a/io/init.c b/io/init.c index 3b7db9ca7..e0135f0f5 100644 --- a/io/init.c +++ b/io/init.c @@ -52,6 +52,28 @@ usage(void) exit(1); } +void +init_commands(void) +{ + bmap_init(); + fadvise_init(); + file_init(); + freeze_init(); + fsync_init(); + help_init(); + inject_init(); + mmap_init(); + open_init(); + pread_init(); + prealloc_init(); + pwrite_init(); + quit_init(); + resblks_init(); + sendfile_init(); + shutdown_init(); + truncate_init(); +} + void init( int argc, diff --git a/io/io.h b/io/io.h index eb1c8516f..c305c3d9a 100644 --- a/io/io.h +++ b/io/io.h @@ -69,6 +69,7 @@ extern mmap_region_t *maptable; /* mmap'd region array */ extern int mapcount; /* #entries in the mapping table */ extern mmap_region_t *mapping; /* active mapping table entry */ extern int maplist_f(void); +extern void *check_mapping_range(mmap_region_t *, off64_t, size_t, int); /* * Various xfs_io helper routines/globals @@ -84,3 +85,60 @@ extern int alloc_buffer(ssize_t, int, unsigned int); extern int read_buffer(int, off64_t, long long, long long *, int, int); extern void dump_buffer(off64_t, ssize_t); + +extern void bmap_init(void); +extern void file_init(void); +extern void freeze_init(void); +extern void fsync_init(void); +extern void help_init(void); +extern void inject_init(void); +extern void mmap_init(void); +extern void open_init(void); +extern void pread_init(void); +extern void prealloc_init(void); +extern void pwrite_init(void); +extern void quit_init(void); +extern void truncate_init(void); + +#ifdef HAVE_FADVISE +extern void fadvise_init(void); +#else +#define fadvise_init() do { } while (0) +#endif + +#ifdef HAVE_INJECT +extern void inject_init(void); +#else +#define inject_init() do { } while (0) +#endif + +#ifdef HAVE_RESBLKS +extern void resblks_init(void); +#else +#define resblks_init() do { } while (0) +#endif + +#ifdef HAVE_SENDFILE +extern void sendfile_init(void); +#else +#define sendfile_init() do { } while (0) +#endif + +#ifdef HAVE_SHUTDOWN +extern void shutdown_init(void); +#else +#define shutdown_init() do { } while (0) +#endif + +#ifdef HAVE_MADVISE +extern void madvise_init(void); +#else +#define madvise_init() do { } while (0) +#endif + +#ifdef HAVE_MINCORE +extern void mincore_init(void); +#else +#define mincore_init() do { } while (0) +#endif + diff --git a/io/madvise.c b/io/madvise.c new file mode 100644 index 000000000..a687c33cc --- /dev/null +++ b/io/madvise.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#include +#include +#include "command.h" +#include "input.h" +#include "init.h" +#include "io.h" + +static cmdinfo_t madvise_cmd; + +static void +madvise_help(void) +{ + printf(_( +"\n" +" advise the page cache about access patterns expected for a mapping\n" +"\n" +" Modifies page cache behavior when operating on the current mapping.\n" +" The range arguments are required by some advise commands ([*] below).\n" +" With no arguments, the POSIX_MADV_NORMAL advice is implied.\n" +" -d -- don't need these pages (POSIX_MADV_DONTNEED) [*]\n" +" -r -- expect random page references (POSIX_MADV_RANDOM)\n" +" -s -- expect sequential page references (POSIX_MADV_SEQUENTIAL)\n" +" -w -- will need these pages (POSIX_MADV_WILLNEED) [*]\n" +" Notes:\n" +" NORMAL sets the default readahead setting on the file.\n" +" RANDOM sets the readahead setting on the file to zero.\n" +" SEQUENTIAL sets double the default readahead setting on the file.\n" +" WILLNEED forces the maximum readahead.\n" +"\n")); +} + +int +madvise_f( + int argc, + char **argv) +{ + off64_t offset; + size_t length; + void *start; + int advise = MADV_NORMAL; + int c, blocksize, sectsize; + + while ((c = getopt(argc, argv, "drsw")) != EOF) { + switch (c) { + case 'd': /* Don't need these pages */ + advise = MADV_DONTNEED; + break; + case 'r': /* Expect random page references */ + advise = MADV_RANDOM; + break; + case 's': /* Expect sequential page references */ + advise = MADV_SEQUENTIAL; + break; + case 'w': /* Will need these pages */ + advise = MADV_WILLNEED; + break; + default: + return command_usage(&madvise_cmd); + } + } + + if (optind == argc) { + offset = mapping->offset; + length = mapping->length; + } else if (optind == argc - 2) { + init_cvtnum(&blocksize, §size); + offset = cvtnum(blocksize, sectsize, argv[optind]); + if (offset < 0) { + printf(_("non-numeric offset argument -- %s\n"), + argv[optind]); + return 0; + } + optind++; + length = cvtnum(blocksize, sectsize, argv[optind]); + if (length < 0) { + printf(_("non-numeric length argument -- %s\n"), + argv[optind]); + return 0; + } + } else { + return command_usage(&madvise_cmd); + } + + start = check_mapping_range(mapping, offset, length, 1); + if (!start) + return 0; + + if (madvise(start, length, advise) < 0) { + perror("madvise"); + return 0; + } + return 0; +} + +void +madvise_init(void) +{ + madvise_cmd.name = _("madvise"); + madvise_cmd.altname = _("ma"); + madvise_cmd.cfunc = madvise_f; + madvise_cmd.argmin = 0; + madvise_cmd.argmax = -1; + madvise_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK; + madvise_cmd.args = _("[-drsw] [off len]"); + madvise_cmd.oneline = _("give advice about use of memory"); + madvise_cmd.help = madvise_help; + + add_command(&madvise_cmd); +} diff --git a/io/mincore.c b/io/mincore.c new file mode 100644 index 000000000..80b4ac495 --- /dev/null +++ b/io/mincore.c @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#include +#include +#include "command.h" +#include "input.h" +#include "init.h" +#include "io.h" + +static cmdinfo_t mincore_cmd; + +int +mincore_f( + int argc, + char **argv) +{ + off64_t offset; + size_t length; + void *start; + void *current, *previous; + unsigned char *vec; + int i, blocksize, sectsize; + + if (argc == 1) { + offset = mapping->offset; + length = mapping->length; + } else if (argc == 3) { + init_cvtnum(&blocksize, §size); + offset = cvtnum(blocksize, sectsize, argv[1]); + if (offset < 0) { + printf(_("non-numeric offset argument -- %s\n"), + argv[1]); + return 0; + } + length = cvtnum(blocksize, sectsize, argv[2]); + if (length < 0) { + printf(_("non-numeric length argument -- %s\n"), + argv[2]); + return 0; + } + } else { + return command_usage(&mincore_cmd); + } + + start = check_mapping_range(mapping, offset, length, 1); + if (!start) + return 0; + + vec = calloc(length/pagesize, sizeof(unsigned char)); + if (!vec) { + perror("calloc"); + return 0; + } + + if (mincore(start, length, vec) < 0) { + perror("mincore"); + free(vec); + return 0; + } + + previous = NULL; + current = start; + for (i = 0; i < length/pagesize; i++, current += pagesize) { + if (vec[i]) { + if (!previous) { /* print start address */ + printf("0x%lx - ", (unsigned long)current); + previous = start + (i * pagesize); + } + } else if (previous) { /* print end and page count */ + printf(_("0x%lx %lu pages (%llu : %lu)\n"), + (unsigned long)current, + (unsigned long)(current - previous) / pagesize, + (unsigned long long)offset + + (unsigned long long)(previous - start), + (unsigned long)(current - previous)); + previous = NULL; + } + } + if (previous) + printf(_("0x%lx %lu pages (%llu : %lu)\n"), + (unsigned long)current, + (unsigned long)(current - previous) / pagesize, + (unsigned long long)offset + + (unsigned long long)(previous - start), + (unsigned long)(current - previous)); + + free(vec); + return 0; +} + +void +mincore_init(void) +{ + mincore_cmd.name = _("mincore"); + mincore_cmd.altname = _("mi"); + mincore_cmd.cfunc = mincore_f; + mincore_cmd.argmin = 0; + mincore_cmd.argmax = 2; + mincore_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK; + mincore_cmd.args = _("[off len]"); + mincore_cmd.oneline = _("find mapping pages that are memory resident"); + + add_command(&mincore_cmd); +} diff --git a/io/mmap.c b/io/mmap.c index af7c3504b..300eff083 100644 --- a/io/mmap.c +++ b/io/mmap.c @@ -43,8 +43,6 @@ static cmdinfo_t mread_cmd; static cmdinfo_t msync_cmd; static cmdinfo_t munmap_cmd; static cmdinfo_t mwrite_cmd; -static cmdinfo_t madvise_cmd; -static cmdinfo_t mincore_cmd; mmap_region_t *maptable; int mapcount; @@ -79,7 +77,7 @@ print_mapping( (long long)map->offset, (long)map->length); } -static void * +void * check_mapping_range( mmap_region_t *map, off64_t offset, @@ -594,174 +592,6 @@ mwrite_f( return 0; } -static void -madvise_help(void) -{ - printf(_( -"\n" -" advise the page cache about access patterns expected for a mapping\n" -"\n" -" Modifies page cache behavior when operating on the current mapping.\n" -" The range arguments are required by some advise commands ([*] below).\n" -" With no arguments, the POSIX_MADV_NORMAL advice is implied.\n" -" -d -- don't need these pages (POSIX_MADV_DONTNEED) [*]\n" -" -r -- expect random page references (POSIX_MADV_RANDOM)\n" -" -s -- expect sequential page references (POSIX_MADV_SEQUENTIAL)\n" -" -w -- will need these pages (POSIX_MADV_WILLNEED) [*]\n" -" Notes:\n" -" NORMAL sets the default readahead setting on the file.\n" -" RANDOM sets the readahead setting on the file to zero.\n" -" SEQUENTIAL sets double the default readahead setting on the file.\n" -" WILLNEED forces the maximum readahead.\n" -"\n")); -} - -int -madvise_f( - int argc, - char **argv) -{ - off64_t offset; - size_t length; - void *start; - int advise = MADV_NORMAL; - int c, blocksize, sectsize; - - while ((c = getopt(argc, argv, "drsw")) != EOF) { - switch (c) { - case 'd': /* Don't need these pages */ - advise = MADV_DONTNEED; - break; - case 'r': /* Expect random page references */ - advise = MADV_RANDOM; - break; - case 's': /* Expect sequential page references */ - advise = MADV_SEQUENTIAL; - break; - case 'w': /* Will need these pages */ - advise = MADV_WILLNEED; - break; - default: - return command_usage(&madvise_cmd); - } - } - - if (optind == argc) { - offset = mapping->offset; - length = mapping->length; - } else if (optind == argc - 2) { - init_cvtnum(&blocksize, §size); - offset = cvtnum(blocksize, sectsize, argv[optind]); - if (offset < 0) { - printf(_("non-numeric offset argument -- %s\n"), - argv[optind]); - return 0; - } - optind++; - length = cvtnum(blocksize, sectsize, argv[optind]); - if (length < 0) { - printf(_("non-numeric length argument -- %s\n"), - argv[optind]); - return 0; - } - } else { - return command_usage(&madvise_cmd); - } - - start = check_mapping_range(mapping, offset, length, 1); - if (!start) - return 0; - - if (madvise(start, length, advise) < 0) { - perror("madvise"); - return 0; - } - return 0; -} - -#if defined(__sgi__) -int mincore(caddr_t p, size_t s, char *v) { errno = ENOSYS; return -1; } -#endif - -int -mincore_f( - int argc, - char **argv) -{ - off64_t offset; - size_t length; - void *start; - void *current, *previous; - unsigned char *vec; - int i, blocksize, sectsize; - - if (argc == 1) { - offset = mapping->offset; - length = mapping->length; - } else if (argc == 3) { - init_cvtnum(&blocksize, §size); - offset = cvtnum(blocksize, sectsize, argv[1]); - if (offset < 0) { - printf(_("non-numeric offset argument -- %s\n"), - argv[1]); - return 0; - } - length = cvtnum(blocksize, sectsize, argv[2]); - if (length < 0) { - printf(_("non-numeric length argument -- %s\n"), - argv[2]); - return 0; - } - } else { - return command_usage(&mincore_cmd); - } - - start = check_mapping_range(mapping, offset, length, 1); - if (!start) - return 0; - - vec = calloc(length/pagesize, sizeof(unsigned char)); - if (!vec) { - perror("calloc"); - return 0; - } - - if (mincore(start, length, vec) < 0) { - perror("mincore"); - free(vec); - return 0; - } - - previous = NULL; - current = start; - for (i = 0; i < length/pagesize; i++, current += pagesize) { - if (vec[i]) { - if (!previous) { /* print start address */ - printf("0x%lx - ", (unsigned long)current); - previous = start + (i * pagesize); - } - } else if (previous) { /* print end and page count */ - printf(_("0x%lx %lu pages (%llu : %lu)\n"), - (unsigned long)current, - (unsigned long)(current - previous) / pagesize, - (unsigned long long)offset + - (unsigned long long)(previous - start), - (unsigned long)(current - previous)); - previous = NULL; - } - } - if (previous) - printf(_("0x%lx %lu pages (%llu : %lu)\n"), - (unsigned long)current, - (unsigned long)(current - previous) / pagesize, - (unsigned long long)offset + - (unsigned long long)(previous - start), - (unsigned long)(current - previous)); - - free(vec); - return 0; -} - void mmap_init(void) { @@ -816,30 +646,9 @@ mmap_init(void) _("writes data into a region in the current memory mapping"); mwrite_cmd.help = mwrite_help; - madvise_cmd.name = _("madvise"); - madvise_cmd.altname = _("ma"); - madvise_cmd.cfunc = madvise_f; - madvise_cmd.argmin = 0; - madvise_cmd.argmax = -1; - madvise_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK; - madvise_cmd.args = _("[-drsw] [off len]"); - madvise_cmd.oneline = _("give advice about use of memory"); - madvise_cmd.help = madvise_help; - - mincore_cmd.name = _("mincore"); - mincore_cmd.altname = _("mi"); - mincore_cmd.cfunc = mincore_f; - mincore_cmd.argmin = 0; - mincore_cmd.argmax = 2; - mincore_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK; - mincore_cmd.args = _("[off len]"); - mincore_cmd.oneline = _("find mapping pages that are memory resident"); - add_command(&mmap_cmd); add_command(&mread_cmd); add_command(&msync_cmd); add_command(&munmap_cmd); add_command(&mwrite_cmd); - add_command(&madvise_cmd); - add_command(&mincore_cmd); } diff --git a/m4/Makefile b/m4/Makefile index 2d06fec1c..61dccf96e 100644 --- a/m4/Makefile +++ b/m4/Makefile @@ -36,6 +36,7 @@ include $(TOPDIR)/include/builddefs LSRCFILES = \ manual_format.m4 \ package_globals.m4 \ + package_libcdev.m4 \ package_pthread.m4 \ package_types.m4 \ package_utilies.m4 \ diff --git a/m4/package_libcdev.m4 b/m4/package_libcdev.m4 new file mode 100644 index 000000000..d612da272 --- /dev/null +++ b/m4/package_libcdev.m4 @@ -0,0 +1,67 @@ +# +# Check if we have a working fadvise system call +# +AC_DEFUN([AC_HAVE_FADVISE], + [ AC_MSG_CHECKING([for fadvise ]) + AC_TRY_COMPILE([ +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include + ], [ + posix_fadvise(0, 1, 0, 0); + ], have_fadvise=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_fadvise) + ]) + +# +# Check if we have a working madvise system call +# +AC_DEFUN([AC_HAVE_MADVISE], + [ AC_MSG_CHECKING([for madvise ]) + AC_TRY_COMPILE([ +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include + ], [ + posix_madvise(0, 0, MADV_NORMAL); + ], have_madvise=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_madvise) + ]) + +# +# Check if we have a working mincore system call +# +AC_DEFUN([AC_HAVE_MINCORE], + [ AC_MSG_CHECKING([for mincore ]) + AC_TRY_COMPILE([ +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include + ], [ + mincore(0, 0, 0); + ], have_mincore=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_mincore) + ]) + +# +# Check if we have a working sendfile system call +# +AC_DEFUN([AC_HAVE_SENDFILE], + [ AC_MSG_CHECKING([for sendfile ]) + AC_TRY_COMPILE([ +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include + ], [ + sendfile(0, 0, 0, 0); + ], have_sendfile=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_sendfile) + ])