Merge tag 'v3.10.71' into update
authorStricted <info@stricted.net>
Wed, 21 Mar 2018 21:40:50 +0000 (22:40 +0100)
committerStricted <info@stricted.net>
Wed, 21 Mar 2018 21:40:50 +0000 (22:40 +0100)
This is the 3.10.71 stable release

1  2 
Makefile
arch/arm64/kernel/signal32.c
drivers/tty/pty.c
drivers/usb/core/hcd.c
drivers/usb/core/usb.c
fs/binfmt_elf.c
include/linux/usb/hcd.h
kernel/debug/kdb/kdb_main.c
kernel/trace/trace.c

diff --combined Makefile
index 2a4bac8516ebd5917544caf96ad2e92524280053,d8b42f71ea5a6ba92ab3720b2408102248397fe7..1db0cf3eed39abe0045855de7e733a769f2a7849
+++ b/Makefile
@@@ -1,6 -1,6 +1,6 @@@
  VERSION = 3
  PATCHLEVEL = 10
- SUBLEVEL = 70
+ SUBLEVEL = 71
  EXTRAVERSION =
  NAME = TOSSUG Baby Fish
  
@@@ -373,9 -373,7 +373,9 @@@ KBUILD_CFLAGS   := -Wall -Wundef -Wstri
                   -fno-strict-aliasing -fno-common \
                   -Werror-implicit-function-declaration \
                   -Wno-format-security \
 -                 -fno-delete-null-pointer-checks
 +                 -fno-delete-null-pointer-checks \
 +                 -w
 +
  KBUILD_AFLAGS_KERNEL :=
  KBUILD_CFLAGS_KERNEL :=
  KBUILD_AFLAGS   := -D__ASSEMBLY__
index e1b8b9fb274ebc4050254ace826c49760e8c3689,3d478102b1c015df01f7083ac6e3eb47022b2a00..36db9874c0b7e4cf46039e6b58980a90854701da
@@@ -26,7 -26,7 +26,7 @@@
  #include <asm/fpsimd.h>
  #include <asm/signal32.h>
  #include <asm/uaccess.h>
 -#include <asm/unistd32.h>
 +#include <asm/unistd.h>
  
  struct compat_sigcontext {
        /* We always set these two fields to 0 */
@@@ -179,8 -179,7 +179,7 @@@ int copy_siginfo_to_user32(compat_sigin
        case __SI_TIMER:
                 err |= __put_user(from->si_tid, &to->si_tid);
                 err |= __put_user(from->si_overrun, &to->si_overrun);
-                err |= __put_user((compat_uptr_t)(unsigned long)from->si_ptr,
-                                  &to->si_ptr);
+                err |= __put_user(from->si_int, &to->si_int);
                break;
        case __SI_POLL:
                err |= __put_user(from->si_band, &to->si_band);
        case __SI_MESGQ: /* But this is */
                err |= __put_user(from->si_pid, &to->si_pid);
                err |= __put_user(from->si_uid, &to->si_uid);
-               err |= __put_user((compat_uptr_t)(unsigned long)from->si_ptr, &to->si_ptr);
+               err |= __put_user(from->si_int, &to->si_int);
                break;
 +#ifdef __ARCH_SIGSYS
 +      case __SI_SYS:
 +              err |= __put_user((compat_uptr_t)(unsigned long)
 +                              from->si_call_addr, &to->si_call_addr);
 +              err |= __put_user(from->si_syscall, &to->si_syscall);
 +              err |= __put_user(from->si_arch, &to->si_arch);
 +              break;
 +#endif
        default: /* this is just in case for now ... */
                err |= __put_user(from->si_pid, &to->si_pid);
                err |= __put_user(from->si_uid, &to->si_uid);
@@@ -255,7 -246,7 +254,7 @@@ static int compat_preserve_vfp_context(
         * Note that this also saves V16-31, which aren't visible
         * in AArch32.
         */
 -      fpsimd_save_state(fpsimd);
 +      fpsimd_preserve_current_state();
  
        /* Place structure header on the stack */
        __put_user_error(magic, &frame->magic, err);
@@@ -318,8 -309,11 +317,8 @@@ static int compat_restore_vfp_context(s
         * We don't need to touch the exception register, so
         * reload the hardware state.
         */
 -      if (!err) {
 -              preempt_disable();
 -              fpsimd_load_state(&fpsimd);
 -              preempt_enable();
 -      }
 +      if (!err)
 +              fpsimd_update_current_state(&fpsimd);
  
        return err ? -EFAULT : 0;
  }
diff --combined drivers/tty/pty.c
index 8c1b8789690ce9fedb40b422151cc5b6fbb010e2,7cb36813aac2bbded76575f36620d4ec510b1a98..bdfe8ecc731cc173a7fa19368de0f774d8367aa4
@@@ -25,6 -25,7 +25,6 @@@
  #include <linux/slab.h>
  #include <linux/mutex.h>
  
 -
  #ifdef CONFIG_UNIX98_PTYS
  static struct tty_driver *ptm_driver;
  static struct tty_driver *pts_driver;
@@@ -214,6 -215,9 +214,9 @@@ static int pty_signal(struct tty_struc
        unsigned long flags;
        struct pid *pgrp;
  
+       if (sig != SIGINT && sig != SIGQUIT && sig != SIGTSTP)
+               return -EINVAL;
        if (tty->link) {
                spin_lock_irqsave(&tty->link->ctrl_lock, flags);
                pgrp = get_pid(tty->link->pgrp);
diff --combined drivers/usb/core/hcd.c
index c3da308c8b327395e4e6c0c6477e857436588575,cbfd3d14fa5aad4c5ef5b19615391893f468d6bd..ad6b50cca19f509d3d6c0f47744f78d106aa4d2a
@@@ -699,30 -699,18 +699,30 @@@ void usb_hcd_poll_rh_status(struct usb_
        unsigned long   flags;
        char            buffer[6];      /* Any root hubs with > 31 ports? */
  
 +      MYDBG("");
 +
        if (unlikely(!hcd->rh_pollable))
 +      {
 +              MYDBG("");
                return;
 +      }
        if (!hcd->uses_new_polling && !hcd->status_urb)
 +      {
 +              MYDBG("");
                return;
 +      }
  
 +      MYDBG("");
        length = hcd->driver->hub_status_data(hcd, buffer);
 +      MYDBG("");
        if (length > 0) {
 +              MYDBG("");
  
                /* try to complete the status urb */
                spin_lock_irqsave(&hcd_root_hub_lock, flags);
                urb = hcd->status_urb;
                if (urb) {
 +                      MYDBG("");
                        clear_bit(HCD_FLAG_POLL_PENDING, &hcd->flags);
                        hcd->status_urb = NULL;
                        urb->actual_length = length;
                        usb_hcd_giveback_urb(hcd, urb, 0);
                        spin_lock(&hcd_root_hub_lock);
                } else {
 +                      MYDBG("");
                        length = 0;
                        set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags);
                }
                spin_unlock_irqrestore(&hcd_root_hub_lock, flags);
        }
 +      MYDBG("");
  
        /* The USB 2.0 spec says 256 ms.  This is close enough and won't
         * exceed that limit if HZ is 100. The math is more clunky than
         * fire at the same time to give the CPU a break in between */
        if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) :
                        (length == 0 && hcd->status_urb != NULL))
 +      {
 +              MYDBG("");
                mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4));
 +      }
  }
  EXPORT_SYMBOL_GPL(usb_hcd_poll_rh_status);
  
@@@ -1610,6 -1593,7 +1610,7 @@@ static int unlink1(struct usb_hcd *hcd
  int usb_hcd_unlink_urb (struct urb *urb, int status)
  {
        struct usb_hcd          *hcd;
+       struct usb_device       *udev = urb->dev;
        int                     retval = -EIDRM;
        unsigned long           flags;
  
        spin_lock_irqsave(&hcd_urb_unlink_lock, flags);
        if (atomic_read(&urb->use_count) > 0) {
                retval = 0;
-               usb_get_dev(urb->dev);
+               usb_get_dev(udev);
        }
        spin_unlock_irqrestore(&hcd_urb_unlink_lock, flags);
        if (retval == 0) {
                hcd = bus_to_hcd(urb->dev->bus);
                retval = unlink1(hcd, urb, status);
-               usb_put_dev(urb->dev);
+               if (retval == 0)
+                       retval = -EINPROGRESS;
+               else if (retval != -EIDRM && retval != -EBUSY)
+                       dev_dbg(&udev->dev, "hcd_unlink_urb %p fail %d\n",
+                                       urb, retval);
+               usb_put_dev(udev);
        }
-       if (retval == 0)
-               retval = -EINPROGRESS;
-       else if (retval != -EIDRM && retval != -EBUSY)
-               dev_dbg(&urb->dev->dev, "hcd_unlink_urb %p fail %d\n",
-                               urb, retval);
        return retval;
  }
  
diff --combined drivers/usb/core/usb.c
index f7e497884081cc6dd8ab9b674bdc0b1016243ccf,e54b1bdcd66eba02a23b9d3beacdb9b18a344670..bd9b6d4a23dd5436ad2a2e993a131ab99019fe4a
@@@ -270,13 -270,11 +270,13 @@@ static void usb_dev_complete(struct dev
  
  static int usb_dev_suspend(struct device *dev)
  {
 +      MYDBG("");      
        return usb_suspend(dev, PMSG_SUSPEND);
  }
  
  static int usb_dev_resume(struct device *dev)
  {
 +      MYDBG("");      
        return usb_resume(dev, PMSG_RESUME);
  }
  
@@@ -1005,6 -1003,7 +1005,7 @@@ static int __init usb_init(void
                pr_info("%s: USB support disabled\n", usbcore_name);
                return 0;
        }
+       usb_init_pool_max();
  
        retval = usb_debugfs_init();
        if (retval)
diff --combined fs/binfmt_elf.c
index 3feb5e7afe717d767acd95c8dfaf4c60cd47af97,3c4d8797ea9aa3218313cb1e89065cce649fc91d..30839a7d14a99bb88d4df04f851ba307720842e6
@@@ -552,11 -552,12 +552,12 @@@ out
  
  static unsigned long randomize_stack_top(unsigned long stack_top)
  {
-       unsigned int random_variable = 0;
+       unsigned long random_variable = 0;
  
        if ((current->flags & PF_RANDOMIZE) &&
                !(current->personality & ADDR_NO_RANDOMIZE)) {
-               random_variable = get_random_int() & STACK_RND_MASK;
+               random_variable = (unsigned long) get_random_int();
+               random_variable &= STACK_RND_MASK;
                random_variable <<= PAGE_SHIFT;
        }
  #ifdef CONFIG_STACK_GROWSUP
   * Jeremy Fitzhardinge <jeremy@sw.oz.au>
   */
  
 +#ifdef CONFIG_MTK_EXTMEM
 +extern bool extmem_in_mspace(struct vm_area_struct *vma);
 +extern unsigned long get_virt_from_mspace(unsigned long pa);
 +#endif
 +
  /*
   * The purpose of always_dump_vma() is to make sure that special kernel mappings
   * that are useful for post-mortem analysis are included in every core dump.
@@@ -1122,11 -1118,6 +1123,11 @@@ static bool always_dump_vma(struct vm_a
        if (arch_vma_name(vma))
                return true;
  
 +#ifdef CONFIG_MTK_EXTMEM
 +      if (extmem_in_mspace(vma)) {
 +              return true;
 +      }       
 +#endif
        return false;
  }
  
@@@ -2068,8 -2059,6 +2069,8 @@@ static int elf_core_dump(struct coredum
        Elf_Half e_phnum;
        elf_addr_t e_shoff;
  
 +      printk(KERN_WARNING "coredump(%d): start\n", current->pid);
 +
        /*
         * We no longer stop all VM operations.
         * 
        if (!dump_seek(cprm->file, dataoff - foffset))
                goto end_coredump;
  
 +      printk(KERN_WARNING "coredump(%d): write output program header and notes\n", current->pid);
 +
        for (vma = first_vma(current, gate_vma); vma != NULL;
                        vma = next_vma(vma, gate_vma)) {
                unsigned long addr;
  
                end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
  
 +#ifdef CONFIG_MTK_EXTMEM
 +              if (extmem_in_mspace(vma)) {
 +                      void *extmem_va = (void *)get_virt_from_mspace(vma->vm_pgoff << PAGE_SHIFT);
 +                      for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE, extmem_va += PAGE_SIZE) {
 +                              int stop;
 +                              int dump_write_ret = dump_write(cprm->file, extmem_va, PAGE_SIZE);
 +                              stop = ((size += PAGE_SIZE) > cprm->limit) || (!dump_write_ret);
 +                              if (stop) {
 +                                      printk(KERN_WARNING "[EXT_MEM]stop addr:0x%lx, size:%zx, limit:0x%lx, dump_write_ret:%d\n", 
 +                                                      addr, size, cprm->limit, dump_write_ret);
 +                                      goto end_coredump;
 +                              }
 +                      }
 +                      continue;
 +              }
 +#endif
 +
 +              //printk(KERN_WARNING "coredump(%d): write out load vm start:%08lx, end:%08lx\n", current->pid, vma->vm_start, end);
                for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
                        struct page *page;
                        int stop;
                                                    PAGE_SIZE);
                                kunmap(page);
                                page_cache_release(page);
 -                      } else
 +                              if (stop) {
 +                                      printk(KERN_WARNING "coredump(%d): failed to write core dump\n", current->pid);
 +                              }
 +                      } else {
                                stop = !dump_seek(cprm->file, PAGE_SIZE);
 +                              if (stop) {
 +                                      printk(KERN_WARNING "coredump(%d): failed to seek core dump\n", current->pid);
 +                              }
 +                      }
                        if (stop)
                                goto end_coredump;
                }
        }
  
 +      printk(KERN_WARNING "coredump(%d): write loads\n", current->pid);
 +
        if (!elf_core_write_extra_data(cprm->file, &size, cprm->limit))
                goto end_coredump;
  
                        goto end_coredump;
        }
  
 +      printk(KERN_WARNING "coredump(%d): write out completed %lld\n", current->pid, offset);
 +
  end_coredump:
        set_fs(fs);
  
diff --combined include/linux/usb/hcd.h
index 20950743fbf7fb8c560b55e640173229ab48ac60,287b906f5d599def921df8b8a4c099c437869b74..bf4778385baad72977bb7667e01d2d675e2b7456
  
  #include <linux/rwsem.h>
  
 +#ifdef CONFIG_USBIF_COMPLIANCE
 +#define MAX_TOPO_LEVEL                2
 +#else
  #define MAX_TOPO_LEVEL                6
 +#endif
  
  /* This file contains declarations of usbcore internals that are mostly
   * used or exposed by Host Controller Drivers.
@@@ -420,6 -416,7 +420,7 @@@ extern const struct dev_pm_ops usb_hcd_
  #endif /* CONFIG_PCI */
  
  /* pci-ish (pdev null is ok) buffer alloc/mapping support */
+ void usb_init_pool_max(void);
  int hcd_buffer_create(struct usb_hcd *hcd);
  void hcd_buffer_destroy(struct usb_hcd *hcd);
  
index fd31267efb84aa299dbdb6f2879c3b2780addb9b,545241de23bfd82eec3cffb4777a05ad33fe3a5b..51bcfb5e867a7a3f1a7da7b100e9e8fb966b6be0
@@@ -1110,11 -1110,6 +1110,11 @@@ void kdb_set_current_task(struct task_s
        kdb_current_regs = NULL;
  }
  
 +/* Check timeout and force kernel panic if no user input for KE_TIMEOUT_SEC */
 +int check_timeout;
 +int force_panic;
 +unsigned long long enter_time;
 +
  /*
   * kdb_local - The main code for kdb.  This routine is invoked on a
   *    specific processor, it is not global.  The main kdb() routine
@@@ -1142,12 -1137,6 +1142,12 @@@ static int kdb_local(kdb_reason_t reaso
        struct task_struct *kdb_current =
                kdb_curr_task(raw_smp_processor_id());
  
 +      check_timeout = 1;
 +      force_panic = 0;
 +      enter_time = sched_clock();
 +
 +      get_cpu_var(kdb_in_use) = 1;
 +      put_cpu_var(kdb_in_use);
        KDB_DEBUG_STATE("kdb_local 1", reason);
        kdb_go_count = 0;
        if (reason == KDB_REASON_DEBUG) {
@@@ -1306,9 -1295,6 +1306,9 @@@ do_full_getstr
                        kdb_cmderror(diag);
        }
        KDB_DEBUG_STATE("kdb_local 9", diag);
 +      get_cpu_var(kdb_in_use) = 0;
 +      put_cpu_var(kdb_in_use);
 +      
        return diag;
  }
  
@@@ -2546,7 -2532,7 +2546,7 @@@ static int kdb_summary(int argc, const 
  #define K(x) ((x) << (PAGE_SHIFT - 10))
        kdb_printf("\nMemTotal:       %8lu kB\nMemFree:        %8lu kB\n"
                   "Buffers:        %8lu kB\n",
-                  val.totalram, val.freeram, val.bufferram);
+                  K(val.totalram), K(val.freeram), K(val.bufferram));
        return 0;
  }
  
@@@ -2867,10 -2853,6 +2867,10 @@@ static void __init kdb_cmd_init(void
        }
  }
  
 +#ifdef CONFIG_MTK_EXTMEM
 +extern void init_debug_alloc_pool_aligned(void);
 +#endif
 +
  /* Initialize kdb_printf, breakpoint tables and kdb state */
  void __init kdb_init(int lvl)
  {
  
        if (kdb_init_lvl == KDB_INIT_FULL || lvl <= kdb_init_lvl)
                return;
 +
 +#ifdef CONFIG_MTK_EXTMEM
 +      init_debug_alloc_pool_aligned();
 +#endif
 +
        for (i = kdb_init_lvl; i < lvl; i++) {
                switch (i) {
                case KDB_NOT_INITIALIZED:
diff --combined kernel/trace/trace.c
index 56487c31d8c78266ad75c613e9c138a886723728,8d7e8098e7689dfd8be989d393511743334841b2..7920b754458a57e9d7855d1c258a970da2eaa48f
  #include <linux/poll.h>
  #include <linux/nmi.h>
  #include <linux/fs.h>
 +
  #include <linux/sched/rt.h>
  
  #include "trace.h"
  #include "trace_output.h"
  
 +#ifdef CONFIG_MTK_SCHED_TRACERS
 +#include <linux/mtk_ftrace.h>
 +#define CREATE_TRACE_POINTS
 +#include <trace/events/mtk_events.h>
 +EXPORT_TRACEPOINT_SYMBOL(gpu_freq);
 +#endif
 +
 +#ifdef CONFIG_MTK_EXTMEM
 +#include <linux/vmalloc.h>
 +#endif
 +
  /*
   * On boot up, the ring buffer is set to the minimum size, so that
   * we do not waste memory on systems that are not using tracing.
@@@ -297,15 -285,6 +297,15 @@@ int tracing_is_enabled(void
  
  static unsigned long          trace_buf_size = TRACE_BUF_SIZE_DEFAULT;
  
 +#ifdef CONFIG_MTK_SCHED_TRACERS
 +#define CPUX_TRACE_BUF_SIZE_DEFAULT 4194304UL
 +#define CPU0_to_CPUX_RATIO (1.2)
 +extern unsigned int get_max_DRAM_size (void);
 +static unsigned long        trace_buf_size_cpu0 = (CPUX_TRACE_BUF_SIZE_DEFAULT * CPU0_to_CPUX_RATIO);
 +static unsigned long        trace_buf_size_cpuX = CPUX_TRACE_BUF_SIZE_DEFAULT;
 +static unsigned int         trace_buf_size_updated_from_cmdline = 0;
 +#endif
 +
  /* trace_types holds a link list of available tracers. */
  static struct tracer          *trace_types __read_mostly;
  
@@@ -397,17 -376,10 +397,17 @@@ static inline void trace_access_lock_in
  #endif
  
  /* trace_flags holds trace_options default values */
 +#ifdef CONFIG_MTK_FTRACE_DEFAULT_ENABLE
 +unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
 +      TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME |
 +      TRACE_ITER_GRAPH_TIME | TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS |
 +    TRACE_ITER_FUNCTION;
 +#else
  unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
        TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME |
        TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE |
        TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION;
 +#endif
  
  void tracer_tracing_on(struct trace_array *tr)
  {
  void tracing_on(void)
  {
        tracer_tracing_on(&global_trace);
 +#ifdef CONFIG_MTK_SCHED_TRACERS
 +    trace_tracing_on(1, CALLER_ADDR0);
 +#endif
  }
  EXPORT_SYMBOL_GPL(tracing_on);
  
@@@ -672,9 -641,6 +672,9 @@@ void tracer_tracing_off(struct trace_ar
   */
  void tracing_off(void)
  {
 +#ifdef CONFIG_MTK_SCHED_TRACERS
 +    trace_tracing_on(0, CALLER_ADDR0);
 +#endif
        tracer_tracing_off(&global_trace);
  }
  EXPORT_SYMBOL_GPL(tracing_off);
@@@ -712,11 -678,6 +712,11 @@@ static int __init set_buf_size(char *st
        if (buf_size == 0)
                return 0;
        trace_buf_size = buf_size;
 +#ifdef CONFIG_MTK_SCHED_TRACERS
 +    trace_buf_size_cpu0 = 
 +        trace_buf_size_cpuX = buf_size ;
 +    trace_buf_size_updated_from_cmdline = 1;
 +#endif
        return 1;
  }
  __setup("trace_buf_size=", set_buf_size);
@@@ -769,7 -730,6 +769,7 @@@ static const char *trace_options[] = 
        "irq-info",
        "markers",
        "function-trace",
 +      "print-tgid",
        NULL
  };
  
@@@ -1240,7 -1200,6 +1240,7 @@@ void tracing_reset(struct trace_buffer 
        synchronize_sched();
        ring_buffer_reset_cpu(buffer, cpu);
  
 +    printk(KERN_INFO "[ftrace]cpu %d trace reset\n", cpu);
        ring_buffer_record_enable(buffer);
  }
  
@@@ -1262,7 -1221,6 +1262,7 @@@ void tracing_reset_online_cpus(struct t
        for_each_online_cpu(cpu)
                ring_buffer_reset_cpu(buffer, cpu);
  
 +    printk(KERN_INFO "[ftrace]all cpu trace reset\n");
        ring_buffer_record_enable(buffer);
  }
  
@@@ -1281,18 -1239,9 +1281,18 @@@ void tracing_reset_all_online_cpus(void
  
  #define SAVED_CMDLINES 128
  #define NO_CMDLINE_MAP UINT_MAX
 +#ifdef CONFIG_MTK_EXTMEM
 +extern void* extmem_malloc_page_align(size_t bytes);
 +#define SIZEOF_MAP_PID_TO_CMDLINE ((PID_MAX_DEFAULT+1)*sizeof(unsigned))
 +#define SIZEOF_MAP_CMDLINE_TO_PID (SAVED_CMDLINES*sizeof(unsigned))
 +static unsigned* map_pid_to_cmdline = NULL;
 +static unsigned* map_cmdline_to_pid = NULL;
 +#else
  static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
  static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
 +#endif
  static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
 +static unsigned saved_tgids[SAVED_CMDLINES];
  static int cmdline_idx;
  static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;
  
@@@ -1301,23 -1250,8 +1301,23 @@@ static atomic_t trace_record_cmdline_di
  
  static void trace_init_cmdlines(void)
  {
 +#ifdef CONFIG_MTK_EXTMEM
 +      map_pid_to_cmdline = (unsigned *) extmem_malloc_page_align(SIZEOF_MAP_PID_TO_CMDLINE);
 +      if(map_pid_to_cmdline == NULL) {
 +              pr_err("%s[%s] ext memory alloc failed!!!\n", __FILE__, __FUNCTION__);
 +              map_pid_to_cmdline = (unsigned *)vmalloc(SIZEOF_MAP_PID_TO_CMDLINE);
 +      }
 +      map_cmdline_to_pid = (unsigned *) extmem_malloc_page_align(SIZEOF_MAP_CMDLINE_TO_PID);
 +      if(map_pid_to_cmdline == NULL) {
 +              pr_warning("%s[%s] ext memory alloc failed!!!\n", __FILE__, __FUNCTION__);
 +              map_cmdline_to_pid = (unsigned *)vmalloc(SIZEOF_MAP_CMDLINE_TO_PID);
 +      }
 +      memset(map_pid_to_cmdline, NO_CMDLINE_MAP, SIZEOF_MAP_PID_TO_CMDLINE);
 +      memset(map_cmdline_to_pid, NO_CMDLINE_MAP, SIZEOF_MAP_CMDLINE_TO_PID);  
 +#else
        memset(&map_pid_to_cmdline, NO_CMDLINE_MAP, sizeof(map_pid_to_cmdline));
        memset(&map_cmdline_to_pid, NO_CMDLINE_MAP, sizeof(map_cmdline_to_pid));
 +#endif
        cmdline_idx = 0;
  }
  
@@@ -1351,7 -1285,6 +1351,7 @@@ void tracing_start(void
  {
        struct ring_buffer *buffer;
        unsigned long flags;
 +    int reset_ftrace = 0;
  
        if (tracing_disabled)
                return;
                        /* Someone screwed up their debugging */
                        WARN_ON_ONCE(1);
                        global_trace.stop_count = 0;
 +            reset_ftrace = 1;
                }
                goto out;
 -      }
 +      }else
 +        reset_ftrace = 1;
 +
  
        /* Prevent the buffers from switching */
        arch_spin_lock(&ftrace_max_lock);
  
   out:
        raw_spin_unlock_irqrestore(&global_trace.start_lock, flags);
 +
 +#ifdef CONFIG_MTK_SCHED_TRACERS
 +    // reset ring buffer when all readers left
 +    if(reset_ftrace == 1 && global_trace.stop_count == 0)
 +        tracing_reset_online_cpus(&global_trace.trace_buffer);
 +#endif
  }
  
  static void tracing_start_tr(struct trace_array *tr)
@@@ -1519,7 -1443,6 +1519,7 @@@ static int trace_save_cmdline(struct ta
        }
  
        memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
 +      saved_tgids[idx] = tsk->tgid;
  
        arch_spin_unlock(&trace_cmdline_lock);
  
@@@ -1557,25 -1480,6 +1557,25 @@@ void trace_find_cmdline(int pid, char c
        preempt_enable();
  }
  
 +int trace_find_tgid(int pid)
 +{
 +      unsigned map;
 +      int tgid;
 +
 +      preempt_disable();
 +      arch_spin_lock(&trace_cmdline_lock);
 +      map = map_pid_to_cmdline[pid];
 +      if (map != NO_CMDLINE_MAP)
 +              tgid = saved_tgids[map];
 +      else
 +              tgid = -1;
 +
 +      arch_spin_unlock(&trace_cmdline_lock);
 +      preempt_enable();
 +
 +      return tgid;
 +}
 +
  void tracing_record_cmdline(struct task_struct *tsk)
  {
        if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on())
@@@ -2032,8 -1936,7 +2032,8 @@@ void trace_printk_init_buffers(void
        pr_info("ftrace: Allocated trace_printk buffers\n");
  
        /* Expand the buffers to set size */
 -      tracing_update_buffers();
 +    /* M: avoid to expand buffer because of trace_printk in kernel */
 +      /* tracing_update_buffers(); */
  
        buffers_allocated = 1;
  
@@@ -2522,9 -2425,6 +2522,9 @@@ static void print_event_info(struct tra
        get_total_entries(buf, &total, &entries);
        seq_printf(m, "# entries-in-buffer/entries-written: %lu/%lu   #P:%d\n",
                   entries, total, num_online_cpus());
 +#ifdef CONFIG_MTK_SCHED_TRACERS
 +    print_enabled_events(m);
 +#endif
        seq_puts(m, "#\n");
  }
  
@@@ -2535,13 -2435,6 +2535,13 @@@ static void print_func_help_header(stru
        seq_puts(m, "#              | |       |          |         |\n");
  }
  
 +static void print_func_help_header_tgid(struct trace_buffer *buf, struct seq_file *m)
 +{
 +      print_event_info(buf, m);
 +      seq_puts(m, "#           TASK-PID    TGID   CPU#      TIMESTAMP  FUNCTION\n");
 +      seq_puts(m, "#              | |        |      |          |         |\n");
 +}
 +
  static void print_func_help_header_irq(struct trace_buffer *buf, struct seq_file *m)
  {
        print_event_info(buf, m);
        seq_puts(m, "#              | |       |   ||||       |         |\n");
  }
  
 +static void print_func_help_header_irq_tgid(struct trace_buffer *buf, struct seq_file *m)
 +{
 +      print_event_info(buf, m);
 +      seq_puts(m, "#                                      _-----=> irqs-off\n");
 +      seq_puts(m, "#                                     / _----=> need-resched\n");
 +      seq_puts(m, "#                                    | / _---=> hardirq/softirq\n");
 +      seq_puts(m, "#                                    || / _--=> preempt-depth\n");
 +      seq_puts(m, "#                                    ||| /     delay\n");
 +      seq_puts(m, "#           TASK-PID    TGID   CPU#  ||||    TIMESTAMP  FUNCTION\n");
 +      seq_puts(m, "#              | |        |      |   ||||       |         |\n");
 +}
 +
  void
  print_trace_header(struct seq_file *m, struct trace_iterator *iter)
  {
@@@ -2866,15 -2747,9 +2866,15 @@@ void trace_default_header(struct seq_fi
        } else {
                if (!(trace_flags & TRACE_ITER_VERBOSE)) {
                        if (trace_flags & TRACE_ITER_IRQ_INFO)
 -                              print_func_help_header_irq(iter->trace_buffer, m);
 +                              if (trace_flags & TRACE_ITER_TGID)
 +                                      print_func_help_header_irq_tgid(iter->trace_buffer, m);
 +                              else
 +                                      print_func_help_header_irq(iter->trace_buffer, m);
                        else
 -                              print_func_help_header(iter->trace_buffer, m);
 +                              if (trace_flags & TRACE_ITER_TGID)
 +                                      print_func_help_header_tgid(iter->trace_buffer, m);
 +                              else
 +                                      print_func_help_header(iter->trace_buffer, m);
                }
        }
  }
@@@ -3140,7 -3015,6 +3140,7 @@@ static int tracing_release(struct inod
        if (iter->trace && iter->trace->close)
                iter->trace->close(iter);
  
 +    printk(KERN_INFO "[ftrace]end reading trace file\n");
        if (!iter->snapshot)
                /* reenable tracing if it was previously enabled */
                tracing_start_tr(tr);
@@@ -3195,7 -3069,6 +3195,7 @@@ static int tracing_open(struct inode *i
        }
  
        if (file->f_mode & FMODE_READ) {
 +        printk(KERN_INFO "[ftrace]start reading trace file\n");
                iter = __tracing_open(inode, file, false);
                if (IS_ERR(iter))
                        ret = PTR_ERR(iter);
@@@ -3728,53 -3601,9 +3728,53 @@@ tracing_saved_cmdlines_read(struct fil
  }
  
  static const struct file_operations tracing_saved_cmdlines_fops = {
 -    .open       = tracing_open_generic,
 -    .read       = tracing_saved_cmdlines_read,
 -    .llseek   = generic_file_llseek,
 +      .open   = tracing_open_generic,
 +      .read   = tracing_saved_cmdlines_read,
 +      .llseek = generic_file_llseek,
 +};
 +
 +static ssize_t
 +tracing_saved_tgids_read(struct file *file, char __user *ubuf,
 +                              size_t cnt, loff_t *ppos)
 +{
 +      char *file_buf;
 +      char *buf;
 +      int len = 0;
 +      int pid;
 +      int i;
 +
 +      file_buf = kmalloc(SAVED_CMDLINES*(16+1+16), GFP_KERNEL);
 +      if (!file_buf)
 +              return -ENOMEM;
 +
 +      buf = file_buf;
 +
 +      for (i = 0; i < SAVED_CMDLINES; i++) {
 +              int tgid;
 +              int r;
 +
 +              pid = map_cmdline_to_pid[i];
 +              if (pid == -1 || pid == NO_CMDLINE_MAP)
 +                      continue;
 +
 +              tgid = trace_find_tgid(pid);
 +              r = sprintf(buf, "%d %d\n", pid, tgid);
 +              buf += r;
 +              len += r;
 +      }
 +
 +      len = simple_read_from_buffer(ubuf, cnt, ppos,
 +                                    file_buf, len);
 +
 +      kfree(file_buf);
 +
 +      return len;
 +}
 +
 +static const struct file_operations tracing_saved_tgids_fops = {
 +      .open   = tracing_open_generic,
 +      .read   = tracing_saved_tgids_read,
 +      .llseek = generic_file_llseek,
  };
  
  static ssize_t
@@@ -3900,7 -3729,7 +3900,7 @@@ static int __tracing_resize_ring_buffer
        return ret;
  }
  
 -static ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
 +ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
                                          unsigned long size, int cpu_id)
  {
        int ret = size;
@@@ -3925,6 -3754,7 +3925,6 @@@ out
        return ret;
  }
  
 -
  /**
   * tracing_update_buffers - used by tracing facility to expand ring buffers
   *
  int tracing_update_buffers(void)
  {
        int ret = 0;
 +#ifdef CONFIG_MTK_FTRACE_DEFAULT_ENABLE 
 +    int i = 0;
 +#endif
  
        mutex_lock(&trace_types_lock);
        if (!ring_buffer_expanded)
 +#ifdef CONFIG_MTK_FTRACE_DEFAULT_ENABLE
 +    {
 +        if(get_max_DRAM_size() >= 0x40000000 && !trace_buf_size_updated_from_cmdline){
 +            trace_buf_size_cpu0 = (CPUX_TRACE_BUF_SIZE_DEFAULT * CPU0_to_CPUX_RATIO * 1.25);
 +            trace_buf_size_cpuX = (CPUX_TRACE_BUF_SIZE_DEFAULT * 1.25);
 +        }
 +
 +        for_each_tracing_cpu(i){
 +            ret = __tracing_resize_ring_buffer(&global_trace, (i==0?trace_buf_size_cpu0:trace_buf_size_cpuX), i); 
 +            if(ret < 0){
 +                printk("KERN_INFO [ftrace]fail to update cpu%d ring buffer to %lu KB \n",
 +                        i, (i==0?(trace_buf_size_cpu0>>10):(trace_buf_size_cpuX>>10)));
 +                break;
 +            }
 +        }
 +    }
 +#else
                ret = __tracing_resize_ring_buffer(&global_trace, trace_buf_size,
                                                RING_BUFFER_ALL_CPUS);
 +#endif
        mutex_unlock(&trace_types_lock);
  
        return ret;
@@@ -4083,7 -3892,6 +4083,7 @@@ tracing_set_trace_write(struct file *fi
        for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
                buf[i] = 0;
  
 +    printk(KERN_INFO "[ftrace]set current_tracer to '%s'\n", buf);
        err = tracing_set_tracer(buf);
        if (err)
                return err;
@@@ -4608,7 -4416,6 +4608,7 @@@ tracing_entries_write(struct file *filp
        struct inode *inode = file_inode(filp);
        struct trace_array *tr = inode->i_private;
        unsigned long val;
 +    int do_drop_cache = 0;
        int ret;
  
        ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
  
        /* value is in KB */
        val <<= 10;
 +resize_ring_buffer:
        ret = tracing_resize_ring_buffer(tr, val, tracing_get_cpu(inode));
 -      if (ret < 0)
 +    if (ret == -ENOMEM && !do_drop_cache) {
 +        do_drop_cache++;
 +        drop_pagecache();
 +        goto resize_ring_buffer;
 +    } else if (ret < 0)
                return ret;
  
        *ppos += cnt;
@@@ -4786,7 -4588,7 +4786,7 @@@ tracing_mark_write(struct file *filp, c
        *fpos += written;
  
   out_unlock:
-       for (i = 0; i < nr_pages; i++){
+       for (i = nr_pages - 1; i >= 0; i--) {
                kunmap_atomic(map_page[i]);
                put_page(pages[i]);
        }
@@@ -6051,20 -5853,12 +6051,20 @@@ rb_simple_write(struct file *filp, cons
                return ret;
  
        if (buffer) {
 +        if(ring_buffer_record_is_on(buffer) ^ val)
 +            printk(KERN_INFO "[ftrace]tracing_on is toggled to %lu\n", val);
                mutex_lock(&trace_types_lock);
                if (val) {
                        tracer_tracing_on(tr);
 +#ifdef CONFIG_MTK_SCHED_TRACERS
 +            trace_tracing_on(val, CALLER_ADDR0);
 +#endif
                        if (tr->current_trace->start)
                                tr->current_trace->start(tr);
                } else {
 +#ifdef CONFIG_MTK_SCHED_TRACERS
 +            trace_tracing_on(val, CALLER_ADDR0);
 +#endif
                        tracer_tracing_off(tr);
                        if (tr->current_trace->stop)
                                tr->current_trace->stop(tr);
@@@ -6085,43 -5879,6 +6085,43 @@@ static const struct file_operations rb_
        .llseek         = default_llseek,
  };
  
 +#ifdef CONFIG_MTK_KERNEL_MARKER
 +static int mt_kernel_marker_enabled = 1;
 +static ssize_t
 +mt_kernel_marker_enabled_simple_read(struct file *filp, char __user *ubuf,
 +             size_t cnt, loff_t *ppos)
 +{
 +      char buf[64];
 +      int r;
 +
 +      r = sprintf(buf, "%d\n", mt_kernel_marker_enabled);
 +
 +      return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
 +}
 +static ssize_t
 +mt_kernel_marker_enabled_simple_write(struct file *filp, const char __user *ubuf,
 +              size_t cnt, loff_t *ppos)
 +{
 +      unsigned long val;
 +      int ret;
 +
 +      ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
 +      if (ret)
 +              return ret;
 +
 +    mt_kernel_marker_enabled = !!val;
 +
 +      (*ppos)++;
 +
 +      return cnt;
 +}
 +static const struct file_operations kernel_marker_simple_fops = {
 +      .open           = tracing_open_generic,
 +      .read           = mt_kernel_marker_enabled_simple_read,
 +      .write          = mt_kernel_marker_enabled_simple_write,
 +      .llseek         = default_llseek,
 +};
 +#endif
  struct dentry *trace_instance_dir;
  
  static void
@@@ -6400,9 -6157,6 +6400,9 @@@ init_tracer_debugfs(struct trace_array 
        trace_create_file("trace_marker", 0220, d_tracer,
                          tr, &tracing_mark_fops);
  
 +      trace_create_file("saved_tgids", 0444, d_tracer,
 +                        tr, &tracing_saved_tgids_fops);
 +
        trace_create_file("trace_clock", 0644, d_tracer, tr,
                          &trace_clock_fops);
  
@@@ -6661,7 -6415,7 +6661,7 @@@ __init static int tracer_alloc_buffers(
        /* Only allocate trace_printk buffers if a trace_printk exists */
        if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt)
                /* Must be called before global_trace.buffer is allocated */
 -              trace_printk_init_buffers();
 +        trace_printk_init_buffers();
  
        /* To save memory, keep the ring buffer size to its minimum */
        if (ring_buffer_expanded)