replace common qcom sources with samsung ones
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
#include <linux/shmem_fs.h>
|
||||
#include <linux/swap.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/sched/clock.h>
|
||||
#include <linux/sched/cputime.h>
|
||||
|
||||
#include "kgsl_reclaim.h"
|
||||
#include "kgsl_sharedmem.h"
|
||||
@@ -31,6 +34,87 @@ struct work_struct reclaim_work;
|
||||
|
||||
static atomic_t kgsl_nr_to_reclaim;
|
||||
|
||||
struct swap_stat {
|
||||
pid_t pid;
|
||||
int nr_pages;
|
||||
u64 nsec_start;
|
||||
u64 nsec_end;
|
||||
u64 nsec_cputime; // use the highest bit for in or out
|
||||
};
|
||||
|
||||
#define SWAP_STAT_HISTORY_SIZE (128)
|
||||
static struct swap_stat swap_stat_hist[SWAP_STAT_HISTORY_SIZE];
|
||||
static unsigned int swap_stat_new_idx;
|
||||
struct mutex swap_stat_lock;
|
||||
|
||||
static void swap_stat_save(struct swap_stat *swap_stat)
|
||||
{
|
||||
unsigned int stat_idx;
|
||||
|
||||
mutex_lock(&swap_stat_lock);
|
||||
stat_idx = swap_stat_new_idx;
|
||||
swap_stat_new_idx = (swap_stat_new_idx + 1) % SWAP_STAT_HISTORY_SIZE;
|
||||
mutex_unlock(&swap_stat_lock);
|
||||
|
||||
swap_stat_hist[stat_idx] = *swap_stat;
|
||||
}
|
||||
|
||||
#define SWAP_STAT_SWAPIN_BIT 63
|
||||
#define SWAP_STAT_SWAPIN (1UL << SWAP_STAT_SWAPIN_BIT)
|
||||
|
||||
static int graphics_swap_proc_show(struct seq_file *m, void *v)
|
||||
{
|
||||
unsigned int stat_idx;
|
||||
struct swap_stat *swap_stat;
|
||||
|
||||
int cnt;
|
||||
u64 wtime_s, wtime_e, wtime_d, cputime_in, cputime;
|
||||
u64 wtime_first = 0;
|
||||
unsigned long wtime_s_rem, wtime_e_rem;
|
||||
int nr_pages;
|
||||
pid_t pid;
|
||||
bool is_swapin;
|
||||
|
||||
stat_idx = swap_stat_new_idx;
|
||||
|
||||
for (cnt = 1; cnt <= SWAP_STAT_HISTORY_SIZE; cnt++) {
|
||||
if (!stat_idx)
|
||||
stat_idx = SWAP_STAT_HISTORY_SIZE - 1;
|
||||
else
|
||||
stat_idx--;
|
||||
swap_stat = &swap_stat_hist[stat_idx];
|
||||
|
||||
wtime_s = swap_stat->nsec_start;
|
||||
if (!wtime_first)
|
||||
wtime_first = wtime_s;
|
||||
if (!wtime_s) /* no data in it */
|
||||
break;
|
||||
if (wtime_first < wtime_s) /* newer data after read */
|
||||
break;
|
||||
wtime_e = swap_stat->nsec_end;
|
||||
wtime_d = wtime_e - wtime_s;
|
||||
wtime_s_rem = do_div(wtime_s, 1000000000);
|
||||
wtime_e_rem = do_div(wtime_e, 1000000000);
|
||||
|
||||
cputime_in = swap_stat->nsec_cputime;
|
||||
cputime = cputime_in & ~SWAP_STAT_SWAPIN;
|
||||
pid = swap_stat->pid;
|
||||
is_swapin = !!(cputime_in & SWAP_STAT_SWAPIN);
|
||||
nr_pages = swap_stat->nr_pages;
|
||||
|
||||
seq_printf(m, "[%03d] [%5lu.%06lu] [%5lu.%06lu] %6u %s %6lu %6lu %6d\n",
|
||||
cnt,
|
||||
(unsigned long)wtime_s, wtime_s_rem / 1000,
|
||||
(unsigned long)wtime_e, wtime_e_rem / 1000,
|
||||
pid, is_swapin ? "IN " : "OUT",
|
||||
(unsigned long)wtime_d / 1000000,
|
||||
(unsigned long)cputime / NSEC_PER_MSEC,
|
||||
nr_pages << (PAGE_SHIFT - 10));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE)
|
||||
static void kgsl_memdesc_clear_unevictable(struct kgsl_process_private *process,
|
||||
struct kgsl_memdesc *memdesc)
|
||||
@@ -173,12 +257,19 @@ int kgsl_reclaim_to_pinned_state(
|
||||
{
|
||||
struct kgsl_mem_entry *entry, *valid_entry;
|
||||
int next = 0, ret = 0, count;
|
||||
unsigned long jiffies_s = jiffies;
|
||||
u64 utime, stime_s, stime_e, stime_d;
|
||||
pid_t pid;
|
||||
struct swap_stat swap_stat;
|
||||
|
||||
mutex_lock(&process->reclaim_lock);
|
||||
|
||||
if (test_bit(KGSL_PROC_PINNED_STATE, &process->state))
|
||||
goto done;
|
||||
|
||||
swap_stat.nsec_start = local_clock();
|
||||
task_cputime(current, &utime, &stime_s);
|
||||
|
||||
count = atomic_read(&process->unpinned_page_count);
|
||||
|
||||
for ( ; ; ) {
|
||||
@@ -206,6 +297,22 @@ int kgsl_reclaim_to_pinned_state(
|
||||
|
||||
trace_kgsl_reclaim_process(process, count, false);
|
||||
set_bit(KGSL_PROC_PINNED_STATE, &process->state);
|
||||
|
||||
task_cputime(current, &utime, &stime_e);
|
||||
stime_d = stime_e - stime_s;
|
||||
pid = pid_nr(process->pid);
|
||||
swap_stat.nsec_end = local_clock();
|
||||
swap_stat.nsec_cputime = stime_d | SWAP_STAT_SWAPIN;
|
||||
swap_stat.pid = pid;
|
||||
swap_stat.nr_pages = count;
|
||||
|
||||
pr_info("kgsl swapin timeJS(ms):%u|%llu tgid:%u nr_unpinned_page:%d->%d\n",
|
||||
jiffies_to_msecs(jiffies - jiffies_s),
|
||||
stime_d / NSEC_PER_MSEC, pid, count,
|
||||
atomic_read(&process->unpinned_page_count));
|
||||
|
||||
swap_stat_save(&swap_stat);
|
||||
|
||||
done:
|
||||
mutex_unlock(&process->reclaim_lock);
|
||||
return ret;
|
||||
@@ -242,9 +349,14 @@ static ssize_t kgsl_proc_state_store(struct kobject *kobj,
|
||||
if (sysfs_streq(buf, "foreground")) {
|
||||
if (!test_and_set_bit(KGSL_PROC_STATE, &process->state) &&
|
||||
kgsl_process_private_get(process))
|
||||
kgsl_schedule_work(&process->fg_work);
|
||||
kgsl_schedule_work_highprio(&process->fg_work);
|
||||
} else if (sysfs_streq(buf, "background")) {
|
||||
clear_bit(KGSL_PROC_STATE, &process->state);
|
||||
if (test_and_clear_bit(KGSL_PROC_STATE, &process->state)
|
||||
&& kgsl_process_private_get(process)) {
|
||||
kgsl_schedule_work_highprio(&process->bg_work);
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
} else
|
||||
return -EINVAL;
|
||||
|
||||
@@ -397,6 +509,35 @@ static u32 kgsl_reclaim_process(struct kgsl_process_private *process,
|
||||
return (pages_to_reclaim - remaining);
|
||||
}
|
||||
|
||||
static void ppr_kgsl_reclaim_background_work(struct work_struct *work)
|
||||
{
|
||||
u64 utime, stime_s, stime_e, stime_d;
|
||||
u64 nr_reclaimed;
|
||||
pid_t pid;
|
||||
struct kgsl_process_private *process =
|
||||
container_of(work, struct kgsl_process_private, bg_work);
|
||||
|
||||
if (!test_bit(KGSL_PROC_STATE, &process->state)) {
|
||||
struct swap_stat swap_stat;
|
||||
|
||||
swap_stat.nsec_start = local_clock();
|
||||
task_cputime(current, &utime, &stime_s);
|
||||
|
||||
nr_reclaimed = kgsl_reclaim_process(process, kgsl_reclaim_max_page_limit);
|
||||
|
||||
task_cputime(current, &utime, &stime_e);
|
||||
stime_d = stime_e - stime_s;
|
||||
pid = pid_nr(process->pid);
|
||||
swap_stat.nsec_end = local_clock();
|
||||
swap_stat.nsec_cputime = stime_d;
|
||||
swap_stat.pid = pid;
|
||||
swap_stat.nr_pages = nr_reclaimed;
|
||||
swap_stat_save(&swap_stat);
|
||||
}
|
||||
|
||||
kgsl_process_private_put(process);
|
||||
}
|
||||
|
||||
static void kgsl_reclaim_background_work(struct work_struct *work)
|
||||
{
|
||||
u32 bg_proc = 0, nr_pages = atomic_read(&kgsl_nr_to_reclaim);
|
||||
@@ -442,7 +583,7 @@ kgsl_reclaim_shrink_scan_objects(struct shrinker *shrinker,
|
||||
|
||||
atomic_set(&kgsl_nr_to_reclaim, kgsl_nr_to_scan ?
|
||||
kgsl_nr_to_scan : sc->nr_to_scan);
|
||||
kgsl_schedule_work(&reclaim_work);
|
||||
kgsl_schedule_work_normprio(&reclaim_work);
|
||||
|
||||
return atomic_read(&kgsl_nr_to_reclaim);
|
||||
}
|
||||
@@ -472,6 +613,7 @@ void kgsl_reclaim_proc_private_init(struct kgsl_process_private *process)
|
||||
{
|
||||
mutex_init(&process->reclaim_lock);
|
||||
INIT_WORK(&process->fg_work, kgsl_reclaim_foreground_work);
|
||||
INIT_WORK(&process->bg_work, ppr_kgsl_reclaim_background_work);
|
||||
set_bit(KGSL_PROC_PINNED_STATE, &process->state);
|
||||
set_bit(KGSL_PROC_STATE, &process->state);
|
||||
atomic_set(&process->unpinned_page_count, 0);
|
||||
@@ -548,6 +690,9 @@ int kgsl_reclaim_init(void)
|
||||
|
||||
INIT_WORK(&reclaim_work, kgsl_reclaim_background_work);
|
||||
|
||||
mutex_init(&swap_stat_lock);
|
||||
proc_create_single("graphics_swap", 0444, NULL,
|
||||
graphics_swap_proc_show);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user