SIONlib  1.7.4
Scalable I/O library for parallel access to task-local files
sion_hints.c
1 /****************************************************************************
2 ** SIONLIB http://www.fz-juelich.de/jsc/sionlib **
3 *****************************************************************************
4 ** Copyright (c) 2008-2019 **
5 ** Forschungszentrum Juelich, Juelich Supercomputing Centre **
6 ** **
7 ** See the file COPYRIGHT in the package base directory for details **
8 ****************************************************************************/
9 #define _XOPEN_SOURCE 700
10 
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <time.h>
15 #include <assert.h>
16 
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <fcntl.h>
20 #include <unistd.h>
21 
22 
23 #include "sion.h"
24 #include "sion_debug.h"
25 #include "sion_internal.h"
26 #include "sion_hints.h"
27 #include "sion_hints_gpfs.h"
28 
29 
30 #if defined(_SION_LINUX)
31 #elif defined(_SION_AIX)
32 #elif defined(_SION_BGP)
33 #endif
34 
35 
36 /*
37 
38 
39  */
40 
47 int _sion_hints_check_env(_sion_filedesc *sion_filedesc) {
48  const char *t;
49  int rc = SION_SUCCESS;
50 
51  t = _sion_getenv("SION_HINTS");
52  if(t) {
53  if(atoi(t) == 1) {
54  sion_filedesc->usehints=1;
55  } else {
56  sion_filedesc->usehints=0;
57  }
58  }
59 
60 #ifdef SION_HINTS_LINUX
61  sion_filedesc->hinttype=SION_HINTS_TYPE_LINUX;
62 #endif
63 #ifdef SION_HINTS_GPFS
64  sion_filedesc->hinttype=SION_HINTS_TYPE_GPFS;
65 #endif
66 
67  t = _sion_getenv("SION_HINT_TYPE_GPFS");
68  if(t) {
69  if(atoi(t) == 1) {
70  sion_filedesc->hinttype=SION_HINTS_TYPE_GPFS;
71  }
72  }
73  t = _sion_getenv("SION_HINT_TYPE_LINUX");
74  if(t) {
75  if(atoi(t) == 1) {
76  sion_filedesc->hinttype=SION_HINTS_TYPE_LINUX;
77  }
78  }
79 
80 
81  DPRINTFP((2, "_sion_hints_check_env", -1, "usehints=%d hinttype=%d\n", sion_filedesc->usehints, sion_filedesc->hinttype));
82 
83  return (rc);
84 }
85 
86 
94 int _sion_apply_hints(_sion_filedesc *sion_filedesc, int access_type) {
95  int rc=SION_SUCCESS;
96 
97  DPRINTFP((2, "_sion_apply_hints", -1, "start usehints=%d hinttype=%d access_type=%d\n",
98  sion_filedesc->usehints,sion_filedesc->hinttype,access_type));
99 
100  if(!sion_filedesc->usehints) {
101  return(rc);
102  }
103 
104 #ifdef SION_HINTS_LINUX
105  if(sion_filedesc->hinttype==SION_HINTS_TYPE_LINUX) {
106  DPRINTFP((2, "_sion_apply_hints", -1, "apply Linux hints\n"));
107  int fd=_sion_file_get_fd(sion_filedesc->fileptr);
108  int iswrite=sion_filedesc->mode == SION_FILEMODE_WRITE;
109  if(access_type==SION_HINTS_ACCESS_TYPE_METADATABLOCK1) {
110  long long startpos = 0;
111  long long length = _sion_get_size_metadatablock1( sion_filedesc );
112 
113  DPRINTFP((2, "_sion_apply_hints", -1, "apply linux hints for metablock1 (%d,%lld,%lld)\n",fd, startpos, length));
114  rc=_sion_apply_hint_linux_access_range(fd, startpos, length, iswrite);
115  }
116  }
117 #endif
118 
119 #ifdef SION_HINTS_GPFS
120  if(sion_filedesc->hinttype==SION_HINTS_TYPE_GPFS) {
121  int fd=_sion_file_get_fd(sion_filedesc->fileptr);
122  int iswrite=sion_filedesc->mode == SION_FILEMODE_WRITE;
123 
124  if(access_type==SION_HINTS_ACCESS_TYPE_METADATABLOCK1) {
125  long long startpos = 0;
126  long long length = _sion_get_size_metadatablock1( sion_filedesc );
127  DPRINTFP((2, "_sion_apply_hints", -1, "apply GPFS hints for metablock1 (%d,%lld,%lld)\n",fd, startpos, length));
128  rc=_sion_apply_hint_gpfs_access_range(fd, startpos, length, iswrite);
129  }
130 
131  if(access_type==SION_HINTS_ACCESS_TYPE_CHUNK) {
132  long long startpos = sion_filedesc->startpos + sion_filedesc->currentblocknr * sion_filedesc->globalskip;
133  long long length = sion_filedesc->chunksize;
134  DPRINTFP((2, "_sion_apply_hints", -1, "apply GPFS hints (access) for chunk (%d,%lld,%lld)\n",fd, startpos, length));
135  rc=_sion_apply_hint_gpfs_access_range(fd, startpos, length, iswrite);
136  }
137 
138  if(access_type==SION_HINTS_FREE_TYPE_CHUNK) {
139  long long startpos = sion_filedesc->startpos + sion_filedesc->currentblocknr * sion_filedesc->globalskip;
140  long long length = sion_filedesc->chunksize;
141  DPRINTFP((2, "_sion_apply_hints", -1, "apply GPFS hints (free) for metablock1 (%d,%lld,%lld)\n",fd, startpos, length));
142  rc=_sion_apply_hint_gpfs_free_range(fd, startpos, length, iswrite);
143  }
144 
145  }
146 #endif
147 
148 
149  return (rc);
150 }
151 
152 
Sion File Descriptor Structure.
Definition: sion_filedesc.h:79
int _sion_file_get_fd(_sion_fileptr *sion_fileptr)
Utility function: Get POSIX fp.
Definition: sion_file.c:376
char * _sion_getenv(const char *name)
#define SION_HINTS_TYPE_GPFS
Definition: sion_filedesc.h:52
#define SION_HINTS_TYPE_LINUX
Definition: sion_filedesc.h:51
sion_int32 currentblocknr
Definition: sion_filedesc.h:97
#define SION_FILEMODE_WRITE
Definition: sion_filedesc.h:38
_sion_fileptr * fileptr
Definition: sion_filedesc.h:82