mripard / sunxi-mali

GNU General Public License v2.0
100 stars 54 forks source link

DEVFREQ fps setting not working #24

Closed ghost closed 6 years ago

ghost commented 6 years ago

Because 60fps is too fast. It's overheating. I have speakers connected to the same two-port USB adapter as the Orange Pi. When CPU is working at 480 Mhz, I hear a little noise. When at 1.2Ghz, average noise. When GPU is working, the noise is crackling loud! And after some time reset happens. The noise isn't a problem. I can just turn off the speakers. It's just a picture.

ghost commented 6 years ago

Aha! There's mali_desired_fps in mali_dvfs_policy.c. How to change without recompile?

ghost commented 6 years ago

/sys/module/mali/parameters/mali_desired_fps

ghost commented 6 years ago

sudo modprobe -r mali sudo modprobe mali mali_desired_fps=24 cat /sys/module/mali/parameters/mali_desired_fps 24 Hooray!

ghost commented 6 years ago

And don't forget about mali_max_system_fps, too.

ghost commented 6 years ago

But, still need to disable vsync.

ghost commented 6 years ago

Or maybe enable?

ghost commented 6 years ago

It's useless setting. The real thing is MALI_PERCENTAGE_TO_UTILIZATION_FRACTION. One can't do lower without changing that.

ghost commented 6 years ago

Well, MAX_PERFORMANCE_VALUE is a better way.

sergey-suloev commented 6 years ago

@bckpkol very nice findings! May I ask you concatenate all things that you found and prepare a short info block for README file ? This may be helpful for others.

ghost commented 6 years ago

That still got it down only to 40-50 fps. Trying to divide target_clk_mhz by 4.

ghost commented 6 years ago

Also about findings. 128mb is too much. But 96mb is just enough.

ghost commented 6 years ago

It seems that my mali400 is overclocked. I'll try to find out why.

ghost commented 6 years ago

I want to add some debug in mali_platform_device->dev.platform_data->set_freq(). Where can I do that?

ghost commented 6 years ago

Did you thought about a possibility driver doesn't change clock at all? Crazy idea: replace all mali_gpu_set_freq(bla) bla=0.

ghost commented 6 years ago

Even that crazy idea can't help me. 45-54fps and crackling in speakers still. Anyone has the idea about disabling vsync? And did you thought about a possibility driver doesn't change clock at all?

ghost commented 6 years ago

Looks like I should define CONFIG_MALI_DVFS :)

giuliobenetti commented 6 years ago

@bckpkol dvfs will scale frequency, but I think that es2 gears app will use 100% of gpu. Otherwise check if min and max frequency parameters do exist

ghost commented 6 years ago

What are those parameters? I did mali_gpu_set_freq(0) and target_clk_mhz=0. ADD: static mali_bool mali_dfvs_enabled=MALI_FALSE - is that the cause?

ghost commented 6 years ago

Aha! dmesg. [] Mali DVFS init: platform function callback incomplete, need check mali_gpu_device_data in platform . That is the cause. Please agree. That's why mali_dfvs_enabled didn't got enabled. What can I do with that issue?

ghost commented 6 years ago

Don't say "es2gears will use 100%". I ran megaglest 16bit 32x32 textures 96mb vram without lag. System didn't crashed before I won. I was lucky.

ghost commented 6 years ago
_mali_osk_errcode_t mali_dvfs_policy_init(void)
{
    _mali_osk_device_data data;
    _mali_osk_errcode_t err = _MALI_OSK_ERR_OK;

    if (_MALI_OSK_ERR_OK == _mali_osk_device_data_get(&data)) {
        if ((NULL != data.get_clock_info) && (NULL != data.set_freq) && (NULL != data.get_freq)) {
            MALI_DEBUG_PRINT(2, ("Mali DVFS init: using arm dvfs policy \n"));

            mali_fps_step1 = mali_max_system_fps / 3;
            mali_fps_step2 = mali_max_system_fps / 5;

            data.get_clock_info(&gpu_clk);

            if (gpu_clk != NULL) {
#ifdef DEBUG
                int i;
                for (i = 0; i < gpu_clk->num_of_steps; i++) {
                    MALI_DEBUG_PRINT(5, ("mali gpu clock info: step%d clock(%d)Hz,vol(%d) \n",
                                 i, gpu_clk->item[i].clock, gpu_clk->item[i].vol));
                }
#endif
            } else {
                MALI_DEBUG_PRINT(2, ("Mali DVFS init: platform didn't define enough info for ddk to do DVFS \n"));
            }

            mali_gpu_get_freq = data.get_freq;
            mali_gpu_set_freq = data.set_freq;

            if ((NULL != gpu_clk) && (gpu_clk->num_of_steps > 0)
                && (NULL != mali_gpu_get_freq) && (NULL != mali_gpu_set_freq)) {
                mali_dvfs_enabled = MALI_TRUE;
            }
        } else {
            MALI_DEBUG_PRINT(2, ("Mali DVFS init: platform function callback incomplete, need check mali_gpu_device_data in platform .\n"));
        }
    } else {
        err = _MALI_OSK_ERR_FAULT;
        MALI_DEBUG_PRINT(2, ("Mali DVFS init: get platform data error .\n"));
    }

    return err;
}
ghost commented 6 years ago

Otherwise check if min and max frequency parameters do exist

You mean, for CPU? Yes they do exist. 420000-1200000 kHz, conservative mode. If your mode isn't set to conservative(mine was set to performance by the vendor), set it. You'll save a lot of temperature. But if you mean for GPU, that's another story.

giuliobenetti commented 6 years ago

@bckpkol I meant gpu frequency. What you are referring is for cpu. I was wondering if there was some parameter in Mali driver.

ghost commented 6 years ago

No. If it is, I didn't know about that. If you know, tell me. Only way I know is via DVFS which isn't working.

ghost commented 6 years ago

If you know another fps setting function than data.set_freq then please tell. If not please also tell.

giuliobenetti commented 6 years ago

@bckpkol I don't know, I was wondering if there was such parameters. Maybe there are in the code, it was only and idea.

ghost commented 6 years ago

Maybe they are. The fps is always almost 60 fps. I don't know how I get it to 40 once, I think the GPU was just hot that time. With DVFS or without, fps is controlled. But I want to control the frequency first. What can I do with that?

ghost commented 6 years ago

There's no point in high frequency if you want 24, 30, even 60 fps. Default settings are too much.

ghost commented 6 years ago

The platform is incomplete. That's why DVFS not working. What if I just copy some source code from the arm platform headers to the sunxi platform headers?

giuliobenetti commented 6 years ago

Can you clarify: "copy code from arm platform to sunxi"? I can't understand.

ghost commented 6 years ago

set_freq exists only in mali_utgard.h as the skeleton. In the arm platform it's set to NULL, in the sunxi platform it does not exist. It has never worked, right?

ghost commented 6 years ago

But arm platform can disable cores.

ghost commented 6 years ago

Besides devfreq there's also utilizations and timer. AFAIK, they do nothing with frequency.

ghost commented 6 years ago
enum mali_executor_state_t {
    EXEC_STATE_NOT_PRESENT, /* Virtual group on Mali-300/400 (do not use) */
    EXEC_STATE_DISABLED,    /* Disabled by core scaling (do not use) */
    EXEC_STATE_EMPTY,       /* No child groups for virtual group (do not use) */
    EXEC_STATE_INACTIVE,    /* Can be used, but must be activate first */
    EXEC_STATE_IDLE,        /* Active and ready to be used */
    EXEC_STATE_WORKING,     /* Executing a job */
};
ghost commented 6 years ago

So, idle is defined as "Active and ready to be used". I don't want it to be idle, I'd prefer lower frequency. Because it should work slow, so no idle.

ghost commented 6 years ago

What will be if I disable PP1 core?

ghost commented 6 years ago
void mali_gpu_utilization_callback(struct mali_gpu_utilization_data *data)
{
    if (1 == mali_core_scaling_enable) {
        mali_core_scaling_update(data);
    }
}

That thing in the arm platform was supposed to disable cores.

sergey-suloev commented 6 years ago

Dear @bckpkol ! Unfortunately, we are all completely lost with what you are trying to achieve! What do you think if you try to explain slowly word by word current situation, what you found, and what you want to make. And please in ONE MESSAGE.

Here is a proposed format: 1) My problem is... 2) I found that ... and that... and that 3) I need this to work a way like ...

I am sure that if someone new comes here and tries to understand what is going on here... well.. there is no way, really.

@giuliobenetti or I am wrong and you are fine with that ?

giuliobenetti commented 6 years ago

@sergey-suloev @bckpkol This repo is not mine. I'm a contributor only. Anyway I fully agree with @sergey-suloev . @bckpkol when I've begun with open-source I've started doing the same as you, but in this way I gained the title(I gave myself), "the stalkest stalker" for someone who reads this :)))) So please, don't bomb with subsequent requests. They are not clear, in this way it's difficult or almost impossible to help you. Also, and I recall my recent experience, everybody is watching this Repo, should have 34 e-mails on his inbox from you :))))) I think I can give the prestigious Title "Stalkest stalker" to you @bckpkol

Ah, use pastebin or something similar for dmesg, logs etc. They are very long

ghost commented 6 years ago

Will try to build with -DUSING_GPU_UTILIZATION=1. I copied utilization handler from arm.

#if USING_GPU_UTILIZATION
    _mali_osk_device_data data;

    if (_MALI_OSK_ERR_OK == _mali_osk_device_data_get(&data)) {
        if (NULL != data.utilization_callback) {
            mali_utilization_callback = data.utilization_callback;
            MALI_DEBUG_PRINT(2, ("Mali GPU Utilization: Utilization handler installed \n"));
        }
    }
#endif /* defined(USING_GPU_UTILIZATION) */

I want to make a cold, low-power workstation. By re-enabling utilization routines. I've found arm_core_scaling files. Copied them to sunxi folder and edited sunxi.c. I think that's clear enough. I will respond if it doesn't crash. Noticed that utilization wasn't setup properly. Makefile now says it conflicts with dvfs. Well, dvfs wasn't working anyway. Well now it writes "utilization handler installed". 'll look if it works. es2gears, roll, hang, reset! I'm enabling core scaling. 'cause I want less power consumption . 'cause I want whole thing colder. By merely copying arm_core_scaling.* to sunxi folder. However it didn't worked. It crashed but was worth a try.

giuliobenetti commented 6 years ago

@bckpkol the form, as for patches is:

What you're doing Why you're doing it How you're doing it

For example: What: "Trying to enable USING_GPU_UTILIZATION" Why: "....." How: "Enable USING_GPU_UTILIZATION and copying utlilization handler from place a link"

Thank you

ghost commented 6 years ago

Anyway, here is the amateur patch https://pastebin.com/ExkFFBfA Will be glad if you can make it work. Has an idea. No, idea is wrong. Finally, core scaling is in mali_executor.c, not in mali_pmu_power_up_down.c. Maybe I should try to examine how it works. Checked - the trouble is not in the core set process.

giuliobenetti commented 6 years ago

@bckpkol you can start in this way:

It's not simple, we all know, but this is the way. Take a look here as hints: https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html# https://www.kernel.org/doc/html/v4.12/process/coding-style.html

And remember for commit log: What Why How

Keep on trying!

ghost commented 6 years ago

https://pastebin.com/bHj6h64K It's dummy patch, it's working and does nothing. Also - I already have a repo, but the update still not ready. Denoiser and saturator are already better, but still no autotuner. Also I want to do vocoder but still in beta.

ghost commented 6 years ago

https://github.com/bckpkol/antiswap - that could prevent OpenGL programs from swapping and so from hanging. Work for Megaglest. Has a release for armhf le. Please build with codeblocks. Hadn't time to patch mali. Was trying to install firefox to that embedded system and succeeded. Generally I'm writing because OpenTomb doesn't work with your drivers. [ 225.926727] Mali<2>: [ 225.926735] bckpkol core disable [ 226.040162] Alignment trap: not handling instruction edc37a00 at [<005039b2>] [ 226.040175] Unhandled fault: alignment exception (0x801) at 0xb56b5021 [ 226.040181] pgd = de0f8000 [ 226.040185] [b56b5021] pgd=56956835, pte=48c6c75f, *ppte=48c6cc7f [ 226.966778] Mali<2>: [ 226.966791] bckpkol core disable And the bus error. Add: with debug level 5 Opentomb is a lot of spam. https://pastebin.com/z1zNUaGC

ghost commented 6 years ago

I think I could understand the concept of cores when I'll want to. But I've never written anything in OpenGL - pygame doesn't count. Can someone of you explain how one frame is changed by another at low level? I want to understand how libMali works. Is there a good tutorial about OpenGL ES? I think I'll use ssloy/tinyrenderer by now. I want to know the last string in dmesg when kernel does crash. How can I save it? I don't have special hardware.

giuliobenetti commented 6 years ago

From your dmesg and your explanation, I can see that a process is taking lot of cma pages. I can't see any kernel panic, anyway it seems that process doesn't release cma memory pages, or driver itself doesn't release memory when requested.

About alignment exception, I would take a look at your dts where you declare cma section. Maybe you need to add alignment attribute, but I'm not sure. You speak abour armhf le. Did you check you're using the same compiler set as the various libraries and programs you are running?

The only way to be sure about all this is to launch OpenTomb or other processes with strace and pastebin log. And launch and pastebin logs and dmesg one by one, describing which app with which log etc.

BTW can you be more schematic on questions as told before? It's not easy to follow you, so it's not easy to help you. Thank you!

ghost commented 6 years ago

Finally, the working patch. At least I think it makes driver use less power. However it works for me. https://pastebin.com/fAsTR8Pv About OpenTomb and MegaGlest - I use ptitSeb's GL wrapper libs (it was tricky to set them system-wide without X crash) which are incomplete and don't support glamor or any other compositing. The issue may also be in this libs. These libs are known to have problems with shaders. Also a bonus - script to compact megaglest data to run at 512 mb ram, 96 mb vram: https://pastebin.com/5AMGpnMD

paolosabatino commented 6 years ago

This issue is a mess, and github is not a forum! Please stick with the original title if applicable, or close the issue!

ghost commented 6 years ago

Well if you include my patch I may close the issue.