HavoqGT
cache_utilities.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright (c) 2013, Lawrence Livermore National Security, LLC.
4  * Produced at the Lawrence Livermore National Laboratory.
5  * Written by Steven Feldman <feldman12@llnl.gov>.
6  * LLNL-CODE-644630.
7  * All rights reserved.
8  *
9  * This file is part of HavoqGT, Version 0.1.
10  * For details, see https://computation.llnl.gov/casc/dcca-pub/dcca/Downloads.html
11  *
12  * Please also read this link – Our Notice and GNU Lesser General Public License.
13  * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
14  *
15  * This program is free software; you can redistribute it and/or modify it under
16  * the terms of the GNU Lesser General Public License (as published by the Free
17  * Software Foundation) version 2.1 dated February 1999.
18  *
19  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
20  * WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY or FITNESS FOR A
21  * PARTICULAR PURPOSE. See the terms and conditions of the GNU General Public
22  * License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License along
25  * with this program; if not, write to the Free Software Foundation, Inc.,
26  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27  *
28  * OUR NOTICE AND TERMS AND CONDITIONS OF THE GNU GENERAL PUBLIC LICENSE
29  *
30  * Our Preamble Notice
31  *
32  * A. This notice is required to be provided under our contract with the
33  * U.S. Department of Energy (DOE). This work was produced at the Lawrence
34  * Livermore National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE.
35  *
36  * B. Neither the United States Government nor Lawrence Livermore National
37  * Security, LLC nor any of their employees, makes any warranty, express or
38  * implied, or assumes any liability or responsibility for the accuracy,
39  * completeness, or usefulness of any information, apparatus, product, or process
40  * disclosed, or represents that its use would not infringe privately-owned rights.
41  *
42  * C. Also, reference herein to any specific commercial products, process, or
43  * services by trade name, trademark, manufacturer or otherwise does not
44  * necessarily constitute or imply its endorsement, recommendation, or favoring by
45  * the United States Government or Lawrence Livermore National Security, LLC. The
46  * views and opinions of authors expressed herein do not necessarily state or
47  * reflect those of the United States Government or Lawrence Livermore National
48  * Security, LLC, and shall not be used for advertising or product endorsement
49  * purposes.
50  *
51  */
52 
53 #ifndef _HAVOQGT_CACHE_UTILI_HPP
54 #define _HAVOQGT_CACHE_UTILI_HPP
55 
56 #include <sys/mman.h>
57 #include <unistd.h>
58 
59 template<typename Vector>
60 char * get_address(Vector &vec) {
61  uintptr_t temp = reinterpret_cast<uintptr_t>(&(vec[0]));
62  temp -= temp % 4096;
63  return reinterpret_cast<char *>(temp);
64 }
65 
66 
67 template<typename Vector>
68 size_t get_length(Vector &vec) {
69  size_t length = vec.size() * sizeof(vec[0]);
70  length += (4096 - length%4096);
71  return length;
72 }
73 
74 
75 template<typename Vector>
76 void advise_vector_rand(Vector &vec) {
77  char * addr = get_address(vec);
78  size_t length = get_length(vec);
79 
80  int t = madvise(addr, length, MADV_RANDOM);
81  assert(t == 0);
82 }
83 
84 
85 template<typename Vector>
86 void flush_advise_vector_dont_need(Vector &vec) {
87  char * addr = get_address(vec);
88  size_t length = get_length(vec);
89 
90  int t = msync(addr, length, MS_SYNC);
91  if (t == 0) {
92  int t2 = madvise(addr, length, MADV_DONTNEED);
93  assert(t2 == 0);
94  } else {
95  assert(t == 0);
96  }
97 
98 }
99 
100 
101 template<typename Vector>
102 void flush_vector(Vector &vec) {
103  char * addr = get_address(vec);
104  size_t length = get_length(vec);
105 
106  int t = msync(addr, length, MS_SYNC);
107  assert(t == 0);
108 }
109 
110 template<typename Vector>
111 void flush_advise_vector(Vector &vec) {
112  char * addr = get_address(vec);
113  size_t length = get_length(vec);
114 
115  int t = msync(addr, length, MS_SYNC);
116  if (t == 0) {
117  int t2 = madvise(addr, length, MADV_DONTNEED);
118  assert(t2 == 0);
119  t2 = madvise(addr, length, MADV_RANDOM);
120  assert(t2 == 0);
121  } else {
122  assert(t == 0);
123  }
124 }
125 
126 #ifndef DIRTY_THRESHOLD_GB
127  #define DIRTY_THRESHOLD_GB 70
128 #endif
129 
131  uint32_t dirty_kb;
132 
133  //FILE *pipe;
134  //pipe = popen("df -h /l/ssd | grep /dev/md0 | awk '{print $3}'", "r" );
135  //fscanf(pipe, "%u", &dirty_kb);
136  //pclose(pipe);
137 
138  return dirty_kb;
139 }
140 
141 void print_system_info(bool print_dimmap) {
142  printf("#################################################################\n");
143  printf("System Information\n");
144  printf("#################################################################\n");
145 
146 
147  printf("\n-----------------------------------------------------------------\n");
148  system("echo \"SLURM_NODELIST = $SLURM_NODELIST \"");
149  printf("-----------------------------------------------------------------\n");
150 
151  printf("\n-----------------------------------------------------------------\n");
152  printf("Tuned Info:\n");
153  printf("-----------------------------------------------------------------\n");
154  system("echo \"/proc/sys/vm/dirty_ratio = $(cat /proc/sys/vm/dirty_ratio)\"");
155  system("echo \"/proc/sys/vm/dirty_background_ratio = $(cat /proc/sys/vm/dirty_background_ratio)\"");
156  system("echo \"/proc/sys/vm/dirty_expire_centisecs = $(cat /proc/sys/vm/dirty_expire_centisecs)\"");
157 
158  printf("\n-----------------------------------------------------------------\n");
159  printf("df -h /l/ssd\n");
160  printf("-----------------------------------------------------------------\n");
161  system("df -h /l/ssd");
162 
163  printf("\n-----------------------------------------------------------------\n");
164  printf("ls /l/ssd\n");
165  printf("-----------------------------------------------------------------\n");
166  system("ls /l/ssd");
167 
168 
169  printf("\n-----------------------------------------------------------------\n");
170  printf("io-stat -m | grep md0 2>&1\n");
171  printf("-----------------------------------------------------------------\n");
172  system("iostat -m | grep Device 2>&1");
173  system("iostat -m | grep md0 2>&1");
174 
175 
176  if (print_dimmap) {
177  printf("\n-----------------------------------------------------------------\n");
178  system("echo \"/proc/di-mmap-runtimeA-stats = $(cat /proc/di-mmap-runtimeA-stats)\"");
179  printf("-----------------------------------------------------------------\n");
180  }
181 
182 
183 
184  printf("\n\n");
185 
186 }
187 
188 void print_dmesg() {
189  printf("\n-----------------------------------------------------------------\n");
190  printf("dmesg\n");
191  printf("-----------------------------------------------------------------\n");
192 
193  system("dmesg");
194 
195  printf("\n\n");
196 }
197 
198 uint32_t get_dirty_pages() {
199  uint32_t dirty_kb;
200 
201  //FILE *pipe;
202  //pipe = popen("grep Dirty /proc/meminfo | awk '{print $2}'", "r" );
203  //fscanf(pipe, "%u", &dirty_kb);
204  //pclose(pipe);
205 
206  return dirty_kb;
207 }
208 
210  uint32_t dirty_kb = get_dirty_pages();
211  const uint32_t dirty_threshold_kb = DIRTY_THRESHOLD_GB * 1000000;
212  return (dirty_kb > dirty_threshold_kb);
213 }
214 
215 
216 void get_io_stat_info(int &r, int &w) {
217  //FILE *pipe;
218  //char str[250];
219  //pipe = popen("iostat -m | grep md0 2>&1 | awk '{printf \"%d %d\\n\" , $5, $6}'", "r" );
220 
221  //fscanf(pipe, "%d %d", &r, &w);
222  //pclose(pipe);
223 };
224 
225 
226 
227 // template<typename mapped_t>
228 // void custom_flush(mapped_t * mapped) {
229 
230 // mapped->flush();
231 
232 // boost::interprocess::mapped_region::advice_types advise;
233 // advise = boost::interprocess::mapped_region::advice_types::advice_dontneed;
234 // assert(mapped->advise(advise));
235 
236 // advise = boost::interprocess::mapped_region::advice_types::advice_random;
237 // assert(mapped->advise(advise));
238 
239 // }
240 
241 
242 
243 // template <typename SegmentManager>
244 // void
245 // delegate_partitioned_graph<SegmentManager>::
246 // try_flush(MPI_Comm comm) {
247 // #if 1
248 // static uint64_t check_id = 0;
249 
250 // if ((m_mpi_rank % 24) == (check_id++) % 24) {
251 
252 // uint32_t dirty_kb;
253 // {
254 // FILE *pipe;
255 // pipe = popen("grep Dirty /proc/meminfo | awk '{print $2}'", "r" );
256 // fscanf(pipe, "%u", &dirty_kb);
257 // pclose(pipe);
258 // }
259 // const uint32_t dirty_threshold_kb = DIRTY_THRESHOLD_GB * 1000000;
260 
261 // if (dirty_kb > dirty_threshold_kb) {
262 // m_flush_func();
263 // }
264 // }
265 
266 
267 // #else
268 // bool do_flush;
269 // if (m_mpi_rank == 0) {
270 // uint32_t dirty_kb;
271 // {
272 // FILE *pipe;
273 // pipe = popen("grep Dirty /proc/meminfo | awk '{print $2}'", "r" );
274 // fscanf(pipe, "%u", &dirty_kb);
275 // pclose(pipe);
276 // }
277 // const uint32_t dirty_threshold_kb = DIRTY_THRESHOLD_GB * 1000000;
278 // do_flush = (dirty_kb > dirty_threshold_kb);
279 // }
280 
281 // MPI_Bcast(&do_flush, 1, mpi_typeof(do_flush), 0, comm);
282 
283 
284 // if (do_flush) {
285 // m_flush_func();
286 // }
287 // #endif
288 // }
289 #endif // _HAVOQGT_CACHE_UTILI_HPP
290 
void flush_vector(Vector &vec)
void print_dmesg()
void flush_advise_vector(Vector &vec)
void advise_vector_rand(Vector &vec)
void flush_advise_vector_dont_need(Vector &vec)
void get_io_stat_info(int &r, int &w)
size_t get_length(Vector &vec)
bool check_dirty_pages()
uint32_t get_dirty_pages()
void print_system_info(bool print_dimmap)
#define DIRTY_THRESHOLD_GB
uint32_t get_disk_utilization()
char * get_address(Vector &vec)