video: hyperv: hyperv_fb: refresh the VM screen by force on VM panic
PATCH v2 1/1 video: hyperv: hyperv_fb: refresh the VM screen by force on VM panic
Currently the VSC has no chance to notify the VSP of the dirty rectangle on VM panic because the notification work is done in a workqueue, and in panic() the kernel typically ends up in an infinite loop, and a typical kernel config has CONFIG_PREEMPT_VOLUNTARY=y and CONFIG_PREEMPT is not set, so a context switch can't happen in panic() and the workqueue won't have a chance to run. As a result, the VM Connection window can't refresh until it's closed and we re-connect to the VM.
We can register a handler on panic_notifier_list: the handler can notify the VSC and switch the framebuffer driver to a "synchronous mode", meaning the VSC flushes any future framebuffer change to the VSP immediately.
v2: removed the MS-TFS line in the commit message
--- drivers/video/fbdev/hyperv_fb.c | 58 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-)
drivers/video/fbdev/hyperv_fb.c +55 -3
@@ -226,11 +226,16 @@ struct hvfb_par {u8 recv_buf[MAX_VMBUS_PKT_SIZE ]; }; +static struct fb_info *hvfb_info; +static uint screen_width =HVFB_WIDTH ;static uint screen_height =HVFB_HEIGHT ;static uint screen_depth;static uint screen_fb_size; +/* If true, the VSC notifies the VSP on every framebuffer change */ +static bool synchronous_fb; +/* Send message to Hyper-V host */ static inline int synthvid_send (struct hv_device *hdev,struct synthvid_msg *msg)
@@ -532,6 +537,20 @@ static void hvfb_update_work(struct work_struct *w)schedule_delayed_work (&par->dwork,HVFB_UPDATE_DELAY ); } +static int hvfb_on_panic (struct notifier_block *nb, +unsigned long e,void *p) +{ +if (hvfb_info) +synthvid_update (hvfb_info); + + synchronous_fb = true; + +return NOTIFY_DONE ; +} + +static struct notifier_block hvfb_panic_nb = { + .notifier_call = hvfb_on_panic, +};/* Framebuffer operation handlers */
@@ -582,14 +601,41 @@ static int hvfb_blank(int blank, struct fb_info *info)return 1 ;/* get fb_blank to set the colormap to all black */ } +static void hvfb_cfb_fillrect (struct fb_info *p, +const struct fb_fillrect *rect) +{ +cfb_fillrect (p, rect); + +if (unlikely (synchronous_fb)) +synthvid_update (p); +} + +static void hvfb_cfb_copyarea (struct fb_info *p, +const struct fb_copyarea *area) +{ +cfb_copyarea (p, area); + +if (unlikely (synchronous_fb)) +synthvid_update (p); +} + +static void hvfb_cfb_imageblit (struct fb_info *p, +const struct fb_image *image) +{ +cfb_imageblit (p, image); + +if (unlikely (synchronous_fb)) +synthvid_update (p); +} +static struct fb_ops hvfb_ops = { .owner =THIS_MODULE , .fb_check_var = hvfb_check_var, .fb_set_par = hvfb_set_par, .fb_setcolreg = hvfb_setcolreg, - .fb_fillrect = cfb_fillrect, - .fb_copyarea = cfb_copyarea, - .fb_imageblit = cfb_imageblit, + .fb_fillrect = hvfb_cfb_fillrect, + .fb_copyarea = hvfb_cfb_copyarea, + .fb_imageblit = hvfb_cfb_imageblit, .fb_blank = hvfb_blank, };
@@ -801,6 +847,9 @@ static int hvfb_probe(struct hv_device *hdev, par->fb_ready = true; + hvfb_info = info; +atomic_notifier_chain_register (&panic_notifier_list, &hvfb_panic_nb); +return 0 ; error:
@@ -820,6 +869,9 @@ static int hvfb_remove(struct hv_device *hdev)struct fb_info *info =hv_get_drvdata (hdev);struct hvfb_par *par = info->par; +atomic_notifier_chain_unregister (&panic_notifier_list, &hvfb_panic_nb); + hvfb_info =NULL ; + par->update = false; par->fb_ready = false;
Signature · 1 line
1.9.1
Quoted 28 lines
-----Original Message-----
From: [email protected] [mailto:driverdev- [email protected]] On Behalf Of Dexuan Cui
Sent: Friday, June 27, 2014 5:35 AM
To: [email protected]; [email protected]; driverdev- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Haiyang Zhang
Subject: [PATCH v2] video: hyperv:hyperv_fb: refresh the VM screen by force on VM panicCurrently the VSC has no chance to notify the VSP of the dirty rectangle on VM
panic because the notification work is done in a workqueue, and inpanic()the
kernel typically ends up in an infinite loop, and a typical kernel config hasCONFIG_PREEMPT_VOLUNTARY=yandCONFIG_PREEMPTis not set, so a context switch
can't happen inpanic()and the workqueue won't have a chance to run. As a result, the VM Connection window can't refresh until it's closed and we re-connect to the VM.We can register a handler on
panic_notifier_list: the handler can notify the VSC and switch the framebuffer driver to a "synchronous mode", meaning
the VSC flushes any future framebuffer change to the VSP immediately.
Quoted 4 lines
v2: removed the MS-TFS line in the commit message
Signed-off-by Dexuan Cui <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>
Hi Greg, Tomi, Jean and all,
Any new comment for the patch?
Thanks,
-- Dexuan
Quoted 123 lines
--- drivers/video/fbdev/hyperv_fb.c | 58 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-)drivers/video/fbdev/hyperv_fb.c +52
-3@@ -226,11 +226,16 @@ struct hvfb_par {u8 recv_buf[MAX_VMBUS_PKT_SIZE ]; }; +static struct fb_info *hvfb_info; +static uint screen_width =HVFB_WIDTH ;static uint screen_height =HVFB_HEIGHT ;static uint screen_depth;static uint screen_fb_size; +/* If true, the VSC notifies the VSP on every framebuffer change */ +static bool synchronous_fb; +/* Send message to Hyper-V host */ static inline int synthvid_send (struct hv_device *hdev,struct synthvid_msg *msg)@@ -532,6 +537,20 @@ static void hvfb_update_work(struct work_struct *w)schedule_delayed_work (&par->dwork,HVFB_UPDATE_DELAY ); } +static int hvfb_on_panic (struct notifier_block *nb, +unsigned long e,void *p) +{ +if (hvfb_info) +synthvid_update (hvfb_info); + + synchronous_fb = true; + +return NOTIFY_DONE ; +} + +static struct notifier_block hvfb_panic_nb = { + .notifier_call = hvfb_on_panic, +};/* Framebuffer operation handlers */ @@ -582,14 +601,41 @@ static int hvfb_blank(int blank, struct fb_info *info)return 1 ;/* get fb_blank to set the colormap to all black */ } +static void hvfb_cfb_fillrect (struct fb_info *p, +const struct fb_fillrect *rect) +{ +cfb_fillrect (p, rect); + +if (unlikely (synchronous_fb)) +synthvid_update (p); +} + +static void hvfb_cfb_copyarea (struct fb_info *p, +const struct fb_copyarea *area) +{ +cfb_copyarea (p, area); + +if (unlikely (synchronous_fb)) +synthvid_update (p); +} + +static void hvfb_cfb_imageblit (struct fb_info *p, +const struct fb_image *image) +{ +cfb_imageblit (p, image); + +if (unlikely (synchronous_fb)) +synthvid_update (p); +} +static struct fb_ops hvfb_ops = { .owner =THIS_MODULE , .fb_check_var = hvfb_check_var, .fb_set_par = hvfb_set_par, .fb_setcolreg = hvfb_setcolreg, - .fb_fillrect = cfb_fillrect, - .fb_copyarea = cfb_copyarea, - .fb_imageblit = cfb_imageblit, + .fb_fillrect = hvfb_cfb_fillrect, + .fb_copyarea = hvfb_cfb_copyarea, + .fb_imageblit = hvfb_cfb_imageblit, .fb_blank = hvfb_blank, };@@ -801,6 +847,9 @@ static int hvfb_probe(struct hv_device *hdev, par->fb_ready = true; + hvfb_info = info; +atomic_notifier_chain_register (&panic_notifier_list, &hvfb_panic_nb); +return 0 ;error:
drivers/video/fbdev/hyperv_fb.c +3
-1@@ -820,6 +869,9 @@ static int hvfb_remove(struct hv_device *hdev)struct fb_info *info =hv_get_drvdata (hdev);struct hvfb_par *par = info->par; +atomic_notifier_chain_unregister (&panic_notifier_list, &hvfb_panic_nb); + hvfb_info =NULL ; + par->update = false; par->fb_ready = false; --1.9.1
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Don't use likely/unlikely unless you have benchmark numbers to show that it makes a speed up.
regards,
dan carpenter
Quoted 11 lines
-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Tuesday, July 8, 2014 17:27 PM
To: Dexuan Cui
Cc: [email protected]; [email protected]; driverdev- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Haiyang Zhang
Subject: Re: [PATCH v2] video: hyperv:hyperv_fb: refresh the VM screen by force on VM panic
Quoted 5 lines
Don't use likely/unlikely unless you have benchmark numbers to show that it makes a speed up.
regards,
dan carpenter
Hi Dan,
Here the variable 'synchronous_fb' is only set to true when the system panics. So before the system panics, it's always 'unlikely'. :-)
Thanks,
-- Dexuan
Quoted 14 lines · Dexuan Cui
Quoted 14 lines
-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Tuesday, July 8, 2014 17:27 PM
To: Dexuan Cui
Cc: [email protected]; [email protected]; driverdev- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Haiyang Zhang
Subject: Re: [PATCH v2] video: hyperv:hyperv_fb: refresh the VM screen by force on VM panicDon't use likely/unlikely unless you have benchmark numbers to show that it makes a speed up.
Quoted 6 lines
Quoted 2 lines
regards,
dan carpenterHi Dan,
Here the variable 'synchronous_fb' is only set to true when the system panics. So before the system panics, it's always 'unlikely'. :-)
Then take advantage of gcc's and your processor's prediction, which knows that 0 is the "common" case and will choose to do the right thing here.
Dan is right, never put those markings in your code unless you can benchmark the difference. Which means in reality, never put them in your code.
thanks,
gerg k-h
Quoted 29 lines
-----Original Message-----
Quoted 4 lines
Quoted 4 lines
From: Dan Carpenter [mailto:[email protected]]
Sent: Tuesday, July 8, 2014 17:27 PM
To: Dexuan Cui
Cc: [email protected]; [email protected];driverdev-
Quoted 4 lines
Quoted 4 lines
[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Haiyang Zhang
Subject: Re: [PATCH v2] video: hyperv:hyperv_fb: refresh the VM screenby
Quoted 3 lines
Quoted 3 lines
force on VM panic
Don't use likely/unlikely unless you have benchmark numbers to show
that
Quoted 7 lines
Quoted 4 lines
it makes a speed up.
regards,
dan carpenterHi Dan,
Here the variable 'synchronous_fb' is only set to true when the systempanics.
Quoted 1 line
So before the system panics, it's always 'unlikely'. :-)
Then take advantage of gcc's and your processor's prediction, which knows that 0 is the "common" case and will choose to do the right thing here.
Quoted 5 lines
Dan is right, never put those markings in your code unless you can benchmark the difference. Which means in reality, never put them in your code.
gerg k-h
OK, let me send out a v3 patch, which will remove the unlikely.
Thanks,
-- Dexuan