aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-02-10 13:05:01 -0500
committerSteven Rostedt <rostedt@goodmis.org>2010-02-10 13:05:01 -0500
commit37fe347963f8f43d95ca0ccd978a769fd6cc96f3 (patch)
treefc874ddcb79e6dbd0a1a54a98aa9bc4256633f00
parentd01bb4f5a3a179f3ce83882ab87a81ef088eb12f (diff)
trace-cmd: Add calc_page_offset() helper routine
Use calc_page_offset() to performe the: offset & (handle->page_size - 1) to prevent any typos and bugs. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-input.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/trace-input.c b/trace-input.c
index 3191510..ce7bd09 100644
--- a/trace-input.c
+++ b/trace-input.c
@@ -517,6 +517,11 @@ static int calc_index(struct tracecmd_input *handle,
517 return (unsigned long)ptr - (unsigned long)handle->cpu_data[cpu].page->map; 517 return (unsigned long)ptr - (unsigned long)handle->cpu_data[cpu].page->map;
518} 518}
519 519
520static unsigned long long calc_page_offset(struct tracecmd_input *handle,
521 unsigned long long offset)
522{
523 return offset & ~(handle->page_size - 1);
524}
520 525
521static int read_page(struct tracecmd_input *handle, off64_t offset, 526static int read_page(struct tracecmd_input *handle, off64_t offset,
522 void *map) 527 void *map)
@@ -876,7 +881,7 @@ find_and_peek_event(struct tracecmd_input *handle, unsigned long long offset,
876 return NULL; 881 return NULL;
877 882
878 /* Move this cpu index to point to this offest */ 883 /* Move this cpu index to point to this offest */
879 page_offset = offset & ~(handle->page_size - 1); 884 page_offset = calc_page_offset(handle, offset);
880 885
881 if (get_page(handle, cpu, page_offset) < 0) 886 if (get_page(handle, cpu, page_offset) < 0)
882 return NULL; 887 return NULL;
@@ -924,7 +929,7 @@ tracecmd_read_at(struct tracecmd_input *handle, unsigned long long offset,
924 unsigned long long page_offset; 929 unsigned long long page_offset;
925 int cpu; 930 int cpu;
926 931
927 page_offset = offset & ~(handle->page_size - 1); 932 page_offset = calc_page_offset(handle, offset);
928 933
929 /* check to see if we have this page already */ 934 /* check to see if we have this page already */
930 for (cpu = 0; cpu < handle->cpus; cpu++) { 935 for (cpu = 0; cpu < handle->cpus; cpu++) {
@@ -969,7 +974,7 @@ int tracecmd_refresh_record(struct tracecmd_input *handle,
969 int index; 974 int index;
970 int ret; 975 int ret;
971 976
972 page_offset = record->offset & ~(handle->page_size - 1); 977 page_offset = calc_page_offset(handle, record->offset);
973 index = record->offset & (handle->page_size - 1); 978 index = record->offset & (handle->page_size - 1);
974 979
975 ret =get_page(handle, record->cpu, page_offset); 980 ret =get_page(handle, record->cpu, page_offset);
@@ -1150,7 +1155,7 @@ tracecmd_set_cpu_to_timestamp(struct tracecmd_input *handle, int cpu,
1150 end = next; 1155 end = next;
1151 1156
1152 next = start + (end - start) / 2; 1157 next = start + (end - start) / 2;
1153 next &= ~(handle->page_size - 1); 1158 next = calc_page_offset(handle, next);
1154 1159
1155 /* Prevent an infinite loop if start and end are a page off */ 1160 /* Prevent an infinite loop if start and end are a page off */
1156 if (next == start) 1161 if (next == start)
@@ -1206,7 +1211,7 @@ int tracecmd_set_cursor(struct tracecmd_input *handle,
1206 return -1; /* cpu does not have this offset. */ 1211 return -1; /* cpu does not have this offset. */
1207 1212
1208 /* Move this cpu index to point to this offest */ 1213 /* Move this cpu index to point to this offest */
1209 page_offset = offset & ~(handle->page_size - 1); 1214 page_offset = calc_page_offset(handle, offset);
1210 1215
1211 if (get_page(handle, cpu, page_offset) < 0) 1216 if (get_page(handle, cpu, page_offset) < 0)
1212 return -1; 1217 return -1;