[Spice-commits] 2 commits - gtk/channel-display.c gtk/channel-display-priv.h gtk/channel-main.c gtk/spice-option.c gtk/spice-session.c gtk/spice-session-priv.h

Yonit Halperin yhalperi at kemper.freedesktop.org
Tue Jan 24 00:35:54 PST 2012


 gtk/channel-display-priv.h |    2 -
 gtk/channel-display.c      |   22 +++++++++-----
 gtk/channel-main.c         |    1 
 gtk/spice-option.c         |   10 ++++++
 gtk/spice-session-priv.h   |   12 +++++++
 gtk/spice-session.c        |   70 ++++++++++++++++++++++++++++++++++++++++++++-
 6 files changed, 107 insertions(+), 10 deletions(-)

New commits:
commit 5e5064c48263fbd18eea799693db618a33d37aa5
Author: Yonit Halperin <yhalperi at redhat.com>
Date:   Mon Jan 16 15:06:55 2012 +0200

    Add command line options for setting the cache size and the glz window size
    
    This options will help us tune and find the optimal values.

diff --git a/gtk/spice-option.c b/gtk/spice-option.c
index 394a07d..9c85c37 100644
--- a/gtk/spice-option.c
+++ b/gtk/spice-option.c
@@ -36,6 +36,8 @@ static char *usbredir_filter = NULL;
 static gboolean smartcard = FALSE;
 static gboolean disable_audio = FALSE;
 static gboolean disable_usbredir = FALSE;
+static gint cache_size = 0;
+static gint glz_window_size = 0;
 
 static void option_version(void)
 {
@@ -79,6 +81,10 @@ GOptionGroup* spice_get_option_group(void)
           N_("Disable USB redirection support"), NULL },
         { "spice-usbredir-filter", '\0', 0, G_OPTION_ARG_STRING, &usbredir_filter,
           N_("Filter for excluding USB devices from auto redirection"), N_("<filter-string>") },
+        { "spice-cache-size", '\0', 0, G_OPTION_ARG_INT, &cache_size,
+          N_("Image cache size"), N_("<bytes>") },
+        { "spice-glz-window-size", '\0', 0, G_OPTION_ARG_INT, &glz_window_size,
+          N_("Glz compression history size"), N_("<bytes>") },
 
         { "spice-debug", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_debug,
           N_("Enable Spice-GTK debugging"), NULL },
@@ -146,4 +152,8 @@ void spice_set_session_option(SpiceSession *session)
         g_object_set(session, "enable-usbredir", FALSE, NULL);
     if (disable_audio)
         g_object_set(session, "enable-audio", FALSE, NULL);
+    if (cache_size)
+        g_object_set(session, "cache-size", cache_size, NULL);
+    if (glz_window_size)
+        g_object_set(session, "glz_window_size", glz_window_size, NULL);
 }
commit 9ca834caf187ee96d981d1ff497dbea80a8159ab
Author: Yonit Halperin <yhalperi at redhat.com>
Date:   Mon Jan 16 13:52:47 2012 +0200

    Change the setting of the images cache size and the glz window size
    
    Set the default sizes to be the same as in the old linux spice client.
    cache_size=20M pixels (instead of 32M), window_size=8M pixels for a 64MB
    dev ram (instead of 16M pixels).

diff --git a/gtk/channel-display-priv.h b/gtk/channel-display-priv.h
index 332d271..eca1787 100644
--- a/gtk/channel-display-priv.h
+++ b/gtk/channel-display-priv.h
@@ -36,8 +36,6 @@
 
 G_BEGIN_DECLS
 
-#define DISPLAY_PIXMAP_CACHE (1024 * 1024 * 32)
-#define GLZ_WINDOW_SIZE      (1024 * 1024 * 16)
 
 typedef struct display_surface {
     RingItem                    link;
diff --git a/gtk/channel-display.c b/gtk/channel-display.c
index ec42829..2473ac6 100644
--- a/gtk/channel-display.c
+++ b/gtk/channel-display.c
@@ -766,13 +766,21 @@ static void emit_invalidate(SpiceChannel *channel, SpiceRect *bbox)
 static void spice_display_channel_up(SpiceChannel *channel)
 {
     SpiceMsgOut *out;
-    SpiceMsgcDisplayInit init = {
-        .pixmap_cache_id            = 1,
-        .pixmap_cache_size          = DISPLAY_PIXMAP_CACHE,
-        .glz_dictionary_id          = 1,
-        .glz_dictionary_window_size = GLZ_WINDOW_SIZE,
-    };
-
+    SpiceSession *s = spice_channel_get_session(channel);
+    SpiceMsgcDisplayInit init;
+    int cache_size;
+    int glz_window_size;
+
+    g_object_get(s,
+                 "cache-size", &cache_size,
+                 "glz-window-size", &glz_window_size,
+                 NULL);
+    SPICE_DEBUG("%s: cache_size %d, glz_window_size %d (bytes)", __FUNCTION__,
+                cache_size, glz_window_size);
+    init.pixmap_cache_id = 1;
+    init.glz_dictionary_id = 1;
+    init.pixmap_cache_size = cache_size / 4; /* pixels */
+    init.glz_dictionary_window_size = glz_window_size / 4; /* pixels */
     out = spice_msg_out_new(channel, SPICE_MSGC_DISPLAY_INIT);
     out->marshallers->msgc_display_init(out->marshaller, &init);
     spice_msg_out_send_internal(out);
diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index ebf660f..b2df547 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -1128,6 +1128,7 @@ static void main_handle_init(SpiceChannel *channel, SpiceMsgIn *in)
                    init->current_mouse_mode);
 
     spice_session_set_mm_time(session, init->multi_media_time);
+    spice_session_set_caches_hints(session, init->ram_hint, init->display_channels_hint);
 
     c->agent_tokens = init->agent_tokens;
     if (init->agent_connected)
diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
index 5df1182..a814cfe 100644
--- a/gtk/spice-session-priv.h
+++ b/gtk/spice-session-priv.h
@@ -27,6 +27,10 @@
 
 G_BEGIN_DECLS
 
+#define IMAGES_CACHE_SIZE_DEFAULT (1024 * 1024 * 80)
+#define MIN_GLZ_WINDOW_SIZE_DEFAULT (1024 * 1024 * 12)
+#define MAX_GLZ_WINDOW_SIZE_DEFAULT MIN((LZ_MAX_WINDOW_SIZE * 4), 1024 * 1024 * 64)
+
 struct _SpiceSessionPrivate {
     char              *host;
     char              *port;
@@ -84,6 +88,11 @@ struct _SpiceSessionPrivate {
     display_cache     images;
     display_cache     palettes;
     SpiceGlzDecoderWindow *glz_window;
+    int               images_cache_size;
+    int               glz_window_size;
+    uint32_t          pci_ram_size;
+    uint32_t          display_channels_count;
+
 
     /* associated objects */
     SpiceAudio        *audio_manager;
@@ -120,6 +129,9 @@ const gchar* spice_session_get_cert_subject(SpiceSession *session);
 const gchar* spice_session_get_ciphers(SpiceSession *session);
 const gchar* spice_session_get_ca_file(SpiceSession *session);
 
+void spice_session_set_caches_hints(SpiceSession *session,
+                                    uint32_t pci_ram_size,
+                                    uint32_t display_channels_count);
 void spice_session_get_caches(SpiceSession *session,
                               display_cache **images,
                               display_cache **palettes,
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index 79ba1b6..33c297a 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -101,6 +101,8 @@ enum {
     PROP_DISABLE_EFFECTS,
     PROP_COLOR_DEPTH,
     PROP_READ_ONLY,
+    PROP_CACHE_SIZE,
+    PROP_GLZ_WINDOW_SIZE,
 };
 
 /* signals */
@@ -407,7 +409,13 @@ static void spice_session_get_property(GObject    *gobject,
         break;
     case PROP_READ_ONLY:
         g_value_set_boolean(value, s->read_only);
-	break;
+        break;
+    case PROP_CACHE_SIZE:
+        g_value_set_int(value, s->images_cache_size);
+        break;
+    case PROP_GLZ_WINDOW_SIZE:
+        g_value_set_int(value, s->glz_window_size);
+        break;
     default:
 	G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
 	break;
@@ -508,6 +516,12 @@ static void spice_session_set_property(GObject      *gobject,
         s->read_only = g_value_get_boolean(value);
         g_object_notify(gobject, "read-only");
         break;
+    case PROP_CACHE_SIZE:
+        s->images_cache_size = g_value_get_int(value);
+        break;
+    case PROP_GLZ_WINDOW_SIZE:
+        s->glz_window_size = g_value_get_int(value);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
         break;
@@ -913,6 +927,36 @@ static void spice_session_class_init(SpiceSessionClass *klass)
                               G_PARAM_CONSTRUCT |
                               G_PARAM_STATIC_STRINGS));
 
+    /**
+     * SpiceSession:cache-size:
+     *
+     * Images cache size. If 0, don't set.
+     *
+     **/
+    g_object_class_install_property
+        (gobject_class, PROP_CACHE_SIZE,
+         g_param_spec_int("cache-size",
+                          "Cache size",
+                          "Images cache size (bytes)",
+                          0, G_MAXINT, 0,
+                          G_PARAM_READWRITE |
+                          G_PARAM_STATIC_STRINGS));
+
+    /**
+     * SpiceSession:glz-window-size:
+     *
+     * Glz window size. If 0, don't set.
+     *
+     **/
+    g_object_class_install_property
+        (gobject_class, PROP_GLZ_WINDOW_SIZE,
+         g_param_spec_int("glz-window-size",
+                          "Glz window size",
+                          "Glz window size (bytes)",
+                          0, LZ_MAX_WINDOW_SIZE * 4, 0,
+                          G_PARAM_READWRITE |
+                          G_PARAM_STATIC_STRINGS));
+
     g_type_class_add_private(klass, sizeof(SpiceSessionPrivate));
 }
 
@@ -1664,3 +1708,27 @@ void spice_session_get_caches(SpiceSession *session,
     if (glz_window)
         *glz_window = s->glz_window;
 }
+
+G_GNUC_INTERNAL
+void spice_session_set_caches_hints(SpiceSession *session,
+                                    uint32_t pci_ram_size,
+                                    uint32_t display_channels_count)
+{
+    SpiceSessionPrivate *s = SPICE_SESSION_GET_PRIVATE(session);
+
+    g_return_if_fail(s != NULL);
+
+    s->pci_ram_size = pci_ram_size;
+    s->display_channels_count = display_channels_count;
+
+    /* TODO: when setting cache and window size, we should consider the client's
+     *       available memory and the number of display channels */
+    if (s->images_cache_size == 0) {
+        s->images_cache_size = IMAGES_CACHE_SIZE_DEFAULT;
+    }
+
+    if (s->glz_window_size == 0) {
+        s->glz_window_size = MIN(MAX_GLZ_WINDOW_SIZE_DEFAULT, pci_ram_size / 2);
+        s->glz_window_size = MAX(MIN_GLZ_WINDOW_SIZE_DEFAULT, s->glz_window_size);
+    }
+}


More information about the Spice-commits mailing list