Merge tag 'v3.10.55' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / trace / ring_buffer.c
index 933d1838488bde4782b1537f3fd108622a233615..2f48d4d90b8354f52babe394c4d1834ee65b5402 100644 (file)
 
 #include <asm/local.h>
 
+#ifdef CONFIG_MTK_EXTMEM
+extern void* extmem_malloc_page_align(size_t bytes);
+extern void extmem_free(void* mem);
+#endif
+
 static void update_pages_handler(struct work_struct *work);
 
 /*
@@ -397,7 +402,11 @@ size_t ring_buffer_page_len(void *page)
  */
 static void free_buffer_page(struct buffer_page *bpage)
 {
+#ifdef CONFIG_MTK_EXTMEM
+       extmem_free((void*) bpage->page);        
+#else
        free_page((unsigned long)bpage->page);
+#endif
        kfree(bpage);
 }
 
@@ -1112,7 +1121,9 @@ static int __rb_allocate_pages(int nr_pages, struct list_head *pages, int cpu)
        struct buffer_page *bpage, *tmp;
 
        for (i = 0; i < nr_pages; i++) {
+#if !defined (CONFIG_MTK_EXTMEM)
                struct page *page;
+#endif
                /*
                 * __GFP_NORETRY flag makes sure that the allocation fails
                 * gracefully without invoking oom-killer and the system is
@@ -1126,11 +1137,19 @@ static int __rb_allocate_pages(int nr_pages, struct list_head *pages, int cpu)
 
                list_add(&bpage->list, pages);
 
+#ifdef CONFIG_MTK_EXTMEM
+               bpage->page = extmem_malloc_page_align(PAGE_SIZE);
+               if(bpage->page == NULL) {
+                       pr_err("%s[%s] ext memory alloc failed!!!\n", __FILE__, __FUNCTION__);
+               goto free_pages;
+       }
+#else
                page = alloc_pages_node(cpu_to_node(cpu),
                                        GFP_KERNEL | __GFP_NORETRY, 0);
                if (!page)
                        goto free_pages;
                bpage->page = page_address(page);
+#endif
                rb_init_page(bpage->page);
        }
 
@@ -1175,7 +1194,9 @@ rb_allocate_cpu_buffer(struct ring_buffer *buffer, int nr_pages, int cpu)
 {
        struct ring_buffer_per_cpu *cpu_buffer;
        struct buffer_page *bpage;
+#if !defined (CONFIG_MTK_EXTMEM)
        struct page *page;
+#endif
        int ret;
 
        cpu_buffer = kzalloc_node(ALIGN(sizeof(*cpu_buffer), cache_line_size()),
@@ -1201,10 +1222,17 @@ rb_allocate_cpu_buffer(struct ring_buffer *buffer, int nr_pages, int cpu)
        rb_check_bpage(cpu_buffer, bpage);
 
        cpu_buffer->reader_page = bpage;
+
+#ifdef CONFIG_MTK_EXTMEM
+       bpage->page = extmem_malloc_page_align(PAGE_SIZE);
+       if(bpage->page == NULL)
+           goto fail_free_reader;
+#else
        page = alloc_pages_node(cpu_to_node(cpu), GFP_KERNEL, 0);
        if (!page)
                goto fail_free_reader;
        bpage->page = page_address(page);
+#endif 
        rb_init_page(bpage->page);
 
        INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
@@ -1980,7 +2008,7 @@ rb_add_time_stamp(struct ring_buffer_event *event, u64 delta)
 
 /**
  * rb_update_event - update event type and data
- * @event: the even to update
+ * @event: the event to update
  * @type: the type of event
  * @length: the size of the event field in the ring buffer
  *
@@ -3755,12 +3783,14 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
                return NULL;
 
        /*
-        * We repeat when a time extend is encountered.
-        * Since the time extend is always attached to a data event,
-        * we should never loop more than once.
-        * (We never hit the following condition more than twice).
+        * We repeat when a time extend is encountered or we hit
+        * the end of the page. Since the time extend is always attached
+        * to a data event, we should never loop more than three times.
+        * Once for going to next page, once on time extend, and
+        * finally once to get the event.
+        * (We never hit the following condition more than thrice).
         */
-       if (RB_WARN_ON(cpu_buffer, ++nr_loops > 2))
+       if (RB_WARN_ON(cpu_buffer, ++nr_loops > 3))
                return NULL;
 
        if (rb_per_cpu_empty(cpu_buffer))