Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory region in framebuffer #65

Merged
merged 1 commit into from
Nov 22, 2024
Merged

Conversation

a1091150
Copy link
Contributor

@a1091150 a1091150 commented Oct 26, 2024

Issue #62
The width of screen may be different from the virtual resolution.
In apps/main.c, the default value of WIDTH and HEIGHT are 640 and 480, but the visual resolution are set to 1920 and 1080 on my machine.
The different width will draw three screens on the display as the below screenshot.

Before:
screen

After:
screen

The reason to use xres_virtual line_length as the width and not to use xres in struct fb_var_screeninfo:
On VirtualBox, the visible resolution of virtual terminal, which switched by ctrl+alt+f3, is set to 800x600, but the virtual solution is set to 2048x2048. On my physical machine, Asus latop and Ubuntu system, these are the same values.

The information from sudo fbset -i on my laptop and VirtualBox.
Laptop:

mode "1920x1080"
    geometry 1920 1080 1920 1080 32
    ....
endmode
Frame buffer device information:
    ....
    LineLength  : 7680
    Accelerator : No

VirtualBox:

mode "800x600"
    geometry 800 600 2048 2048 32
endmode

Frame buffer device information:
    ......
    LineLength  : 8192
    Accelerator : No

@jserv jserv requested a review from shengwen-tw October 26, 2024 15:38
jserv

This comment was marked as duplicate.

backend/fbdev.c Outdated Show resolved Hide resolved
backend/fbdev.c Outdated Show resolved Hide resolved
backend/fbdev.c Outdated Show resolved Hide resolved
backend/fbdev.c Outdated Show resolved Hide resolved
backend/fbdev.c Outdated Show resolved Hide resolved
@a1091150 a1091150 changed the title Fix memory region in framebuffer and cache synchronization Fix memory region in framebuffer and pan display Oct 29, 2024
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve the git commit message to address the consideration of FBIOPAN_DISPLAY.

@a1091150
Copy link
Contributor Author

@shengwen-tw, May you test the pull request on you machine to see if it is running correctly?

@shengwen-tw

This comment was marked as outdated.

@shengwen-tw
Copy link
Collaborator

@shengwen-tw, May you test the pull request on you machine to see if it is running correctly?

I have ran the modification code and have some observations:

Firstly, I want to point out that I wasn’t able to reproduce the issue you encountered, as we previously discussed. From my side, I can only confirm the functionality remains the same.

However, although the framebuffer output appears correct, I noticed that the rendering update is not smooth, with significant lag when dragging windows or even just moving the cursor.

Could you analyze any potential performance bottlenecks in your code and look into ways to address this issue?

@shengwen-tw
Copy link
Collaborator

Please check the video I recorded:
https://www.youtube.com/watch?v=1FK8XkVnP8k

jserv

This comment was marked as duplicate.

@jserv
Copy link
Contributor

jserv commented Nov 4, 2024

Rebase the latest main branch and resolve the conflicts.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use git merge. Always enforce git rebase.

backend/fbdev.c Outdated Show resolved Hide resolved
@a1091150 a1091150 force-pushed the fixVideoSync2 branch 2 times, most recently from acf5c4d to bbc35ff Compare November 4, 2024 14:47
@a1091150
Copy link
Contributor Author

a1091150 commented Nov 4, 2024

Please check the video I recorded: https://www.youtube.com/watch?v=1FK8XkVnP8k

I find out that ioctl(fb_fd, FBIOPAN_DISPLAY, &var); causes your machine lagging, but my laptop and VirtualBox are not. Without it, my laptop can not show the mado's screen.
I see you are using two display, so I plug my laptop another display without the code ioctl(fb_fd, FBIOPAN_DISPLAY, &var);

mado's screen work fine on second display, subtly.

Check the video: https://youtu.be/XvhigZefDfc

The commit bbc35ff removed code ioctl(fb_fd, FBIOPAN_DISPLAY, &var);. I believe this commit is ready to pull (may be?)

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refine the statement "The same setting may not be applied on different hardware" to address the consideration and use scenario.

@jserv jserv changed the title Fix memory region in framebuffer and pan display Fix memory region in framebuffer Nov 4, 2024
@jserv jserv requested a review from shengwen-tw November 4, 2024 17:28
The size of the screen may be different to the virtual resolution. If the size
is less than virtual resolution, it will draw multiple windows on display. Use
`line_length` to calculate instead of the size of the screen.
Changable information like virtual resoultion or setting different information
on virtual terminal may not be applied on different hardware and driver. For
example on VirtualBox, virtual resolution's width and height are 2048 and 2048,
visible resolutions' are 800 and 600, and line length is 2048 * 4. Any setting
from guest machine to these maybe ignored.
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read https://cbea.ms/git-commit/ carefully and enforce the rules.

@shengwen-tw
Copy link
Collaborator

You mentioned that

I find out that ioctl(fb_fd, FBIOPAN_DISPLAY, &var); causes your machine lagging, but my laptop and VirtualBox are not. Without it, my laptop can not show the mado's screen.

Are you planning to open a new pull request to resolve issue #62?

@a1091150
Copy link
Contributor Author

a1091150 commented Nov 7, 2024

Are you planning to open a new pull request to resolve issue #62?

Nope. I notice another drm pull request #69 . The updated may followed and discussed on it.

Issue #62 mentioned some problems:

  1. Different screen size causes multiple windwos and weird behavior(will be fixed by this pull request)
  2. Update and render after switching back to virtual terminal.
  3. ioctl(fb_fd, FBIOPAN_DISPLAY, &var) have different behavior on different machine, mentioned in this pull request before.

For third problem, I suspect it is just my laptop and i915drmfb (Intel DRM) will need this pan display and it is not a bug in Mado but in Intel DRM.

For second problem, I did write some switch code for switching, and I notice the proposed DRM backend (#69). The updated may followed and discussed on it.

@shengwen-tw
Copy link
Collaborator

I did various tests and found that the problem might not be caused by ioctl(fb_fd, FBIOPAN_DISPLAY, &var);, as the issue still occurs on my machine even after removing that line of code. (it also happens with the upstream code, though not consistently.)

If ioctl(fb_fd, FBIOPAN_DISPLAY, &var); resolves the issue you encountered, it would be reasonable to adopt the change you proposed earlier. (But could you clarify why the FBIOPAN_DISPLAY operation helps in this case?)

I suspect that the lag might be due to the button events being sent from the Linux input subsystem we recently integrated, as the current implementation does not ensure atomic updates for mouse events. I may open another new issue once I have a clearer understanding of this phenomenon.

@alanjian85 alanjian85 mentioned this pull request Nov 20, 2024
@jserv
Copy link
Contributor

jserv commented Nov 20, 2024

If ioctl(fb_fd, FBIOPAN_DISPLAY, &var); resolves the issue you encountered, it would be reasonable to adopt the change you proposed earlier. (But could you clarify why the FBIOPAN_DISPLAY operation helps in this case?)

The advantage of using ioctl FBIOPAN_DISPLAY is potential energy efficiency, meaning that the Linux framebuffer driver does not blindly refresh data (especially static frame data), as data updates are managed by the application.

Since the application knows precisely when to refresh the data, the ideal scenario is for it to call FBIOPAN_DISPLAY immediately after updating the data. However, there are drawbacks: first, the application layer must explicitly call FBIOPAN_DISPLAY for display updates; second, if the screen refresh rate is high, the system call overhead introduced by FBIOPAN_DISPLAY can be significant. For Mado development, it is important to account for the potential unintended system overhead caused by the latter concern.

Reference: Structures used by the frame buffer device API

@jserv jserv merged commit e4e0e70 into sysprog21:main Nov 22, 2024
3 checks passed
@jserv
Copy link
Contributor

jserv commented Nov 22, 2024

Thank @a1091150 for contribution!

Check https://cbea.ms/git-commit/ carefully and always enforce the rules, such as Wrap the body at 72 characters. In addition, don't use backtick characters for the sake of terminal compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants