~ubuntu-branches/ubuntu/precise/nvidia-settings/precise-proposed

« back to all changes in this revision

Viewing changes to src/gtk+-2.x/ctkgpu.c

  • Committer: Package Import Robot
  • Author(s): Alberto Milone
  • Date: 2013-12-11 15:23:40 UTC
  • mfrom: (1.3.4)
  • Revision ID: package-import@ubuntu.com-20131211152340-6j6x4ldvu4ll1bu1
Tags: 331.20-0ubuntu0.0.1
* debian/patches/series:
  - Do not apply 01_allow_dark_themes.dpatch.
* debian/patches/07_remove_features_for_legacy.patch:
  - Do not expose features that are not available in the legacy
    drivers.
* debian/patches/08_add_prime_support.patch:
  - Add support for PRIME switching. An additional
    tab provides support for switching between GPUs.
    This is only visible if nvidia-prime (>= 0.5) is
    installed and reports that the system supports
    hybrid graphics. No hard dependency on nvidia-prime
    is therefore required (LP: #1259237).
* debian/patches/09_do_not_complain_if_nvidia_is_missing.patch:
  - Disable the warning dialog since it suggests to run
    nvidia-xconfig, which we don't need. This would also break
    PRIME.
* debian/control.in, debian/postinst.in, debian/postrm.in,
  debian/prerm.in, debian/rules:
  - Drop alternatives and remove templates, as we only have
    one nvidia-settings for all the driver flavours.
* debian/dirs, debian/install,
  debian/nvidia-settings-autostart.desktop,
  debian/nvidia-settings.desktop:
  - Install the icon and the desktop files.
* debian/control:
  - Add ${misc:Depends}.
  - Build depend on libvdpau-dev and depend on libvdpau1.
  - Create transitional packages for 319, 319-updates, 313-updates,
    310, 310-updates, 304, 304-updates, experimental-304, updates.
  - Remove lpia.
  - Depend on screen-resolution-extra (>= 0.14ubuntu2.1).
* debian/rules:
  - Pass the destdir argument in uppercase to match the variable.
  - Add download-sources target.
  - Clean action in rules to target "clean" instead of "distclean".
  - Do not compress .c and .mk files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include <stdio.h>
24
24
#include <stdlib.h>
 
25
#include <string.h>
25
26
 
 
27
#include "msg.h"
26
28
#include "parse.h"
27
29
 
28
30
#include "ctkbanner.h"
35
37
 
36
38
static void probe_displays_received(GtkObject *object, gpointer arg1,
37
39
                                    gpointer user_data);
38
 
static gboolean update_gpu_memory_used(gpointer);
 
40
static gboolean update_gpu_usage(gpointer);
39
41
 
40
42
#define ARRAY_ELEMENTS 16
41
43
#define DEFAULT_UPDATE_GPU_INFO_TIME_INTERVAL 3000
42
44
 
 
45
typedef struct {
 
46
    gint graphics;
 
47
    gint video;
 
48
    gint pcie;
 
49
} utilizationEntry, * utilizationEntryPtr;
 
50
 
43
51
GType ctk_gpu_get_type(
44
52
    void
45
53
)
133
141
    }
134
142
}
135
143
 
136
 
void get_bus_id_str(NvCtrlAttributeHandle *handle,
137
 
                    gchar **pci_bus_id)
 
144
gchar *get_bus_id_str(NvCtrlAttributeHandle *handle)
138
145
{
139
146
    int ret;
140
147
    int pci_domain, pci_bus, pci_device, pci_func;
141
148
    gchar *bus_id;
142
 
    const gchar *__pci_bus_id_unknown = "?@?:?:?";
143
149
 
144
150
    /* NV_CTRL_PCI_DOMAIN & NV_CTRL_PCI_BUS &
145
151
     * NV_CTRL_PCI_DEVICE & NV__CTRL_PCI_FUNCTION
146
152
     */
147
153
 
148
 
    bus_id = NULL;
149
154
    ret = NvCtrlGetAttribute(handle, NV_CTRL_PCI_DOMAIN, &pci_domain);
150
 
    if (ret != NvCtrlSuccess) goto bus_id_fallback;
 
155
    if (ret != NvCtrlSuccess) {
 
156
        return NULL;
 
157
    }
151
158
 
152
159
    ret = NvCtrlGetAttribute(handle, NV_CTRL_PCI_BUS, &pci_bus);
153
 
    if (ret != NvCtrlSuccess) goto bus_id_fallback;
 
160
    if (ret != NvCtrlSuccess) {
 
161
        return NULL;
 
162
    }
154
163
 
155
164
    ret = NvCtrlGetAttribute(handle, NV_CTRL_PCI_DEVICE, &pci_device);
156
 
    if (ret != NvCtrlSuccess) goto bus_id_fallback;
 
165
    if (ret != NvCtrlSuccess) {
 
166
        return NULL;
 
167
    }
157
168
 
158
169
    ret = NvCtrlGetAttribute(handle, NV_CTRL_PCI_FUNCTION, &pci_func);
159
 
    if (ret != NvCtrlSuccess) goto bus_id_fallback;
160
 
 
161
 
    bus_id = malloc(32);
162
 
    if (bus_id) {
163
 
        xconfigFormatPciBusString(bus_id, 32, pci_domain, pci_bus,
164
 
                                  pci_device, pci_func);
 
170
    if (ret != NvCtrlSuccess) {
 
171
        return NULL;
165
172
    }
166
173
 
167
 
 bus_id_fallback:
168
 
 
 
174
    bus_id = g_malloc(32);
169
175
    if (!bus_id) {
170
 
        bus_id = g_strdup(__pci_bus_id_unknown);
 
176
        return NULL;
171
177
    }
172
 
    
173
 
    *pci_bus_id = bus_id;
 
178
    xconfigFormatPciBusString(bus_id, 32, pci_domain, pci_bus,
 
179
                              pci_device, pci_func);
 
180
    return bus_id;
174
181
}
175
182
 
176
183
 
192
199
    GtkWidget *table;
193
200
 
194
201
    char *product_name, *vbios_version, *video_ram, *gpu_memory_text, *irq;
 
202
    char *gpu_uuid;
195
203
    gchar *pci_bus_id;
196
204
    gchar pci_device_id[ARRAY_ELEMENTS];
197
205
    gchar pci_vendor_id[ARRAY_ELEMENTS];
237
245
 
238
246
    ret = NvCtrlGetStringAttribute(handle, NV_CTRL_STRING_PRODUCT_NAME,
239
247
                                   &product_name);
240
 
    if (ret != NvCtrlSuccess) product_name = NULL;
241
 
    
 
248
    if (ret != NvCtrlSuccess) {
 
249
        product_name = NULL;
 
250
    }
 
251
 
 
252
    ret = NvCtrlGetStringAttribute(handle, NV_CTRL_STRING_GPU_UUID,
 
253
                                   &gpu_uuid);
 
254
    if (ret != NvCtrlSuccess) {
 
255
        gpu_uuid = NULL;
 
256
    }
 
257
 
242
258
    /* Get Bus related information */
243
 
    
244
 
    get_bus_id_str(handle, &pci_bus_id);
245
 
    
 
259
 
 
260
    pci_bus_id = get_bus_id_str(handle);
 
261
 
246
262
    /* NV_CTRL_PCI_ID */
247
263
 
248
 
    pci_device_id[ARRAY_ELEMENTS-1] = '\0';
249
 
    pci_vendor_id[ARRAY_ELEMENTS-1] = '\0';
 
264
    memset(&pci_device_id, 0, sizeof(pci_device_id));
 
265
    memset(&pci_vendor_id, 0, sizeof(pci_vendor_id));
250
266
 
251
267
    ret = NvCtrlGetAttribute(handle, NV_CTRL_PCI_ID, &pci_id);
252
268
 
253
 
    if (ret != NvCtrlSuccess) {
254
 
        snprintf(pci_device_id, ARRAY_ELEMENTS, "Unknown");
255
 
        snprintf(pci_vendor_id, ARRAY_ELEMENTS, "Unknown");
256
 
    } else {
 
269
    if (ret == NvCtrlSuccess) {
257
270
        snprintf(pci_device_id, ARRAY_ELEMENTS, "0x%04x", (pci_id & 0xFFFF));
258
271
        snprintf(pci_vendor_id, ARRAY_ELEMENTS, "0x%04x", (pci_id >> 16));
259
272
    }
373
386
 
374
387
    ctk_gpu->handle = handle;
375
388
    ctk_gpu->gpu_cores = (gpu_cores != NULL) ? 1 : 0;
 
389
    ctk_gpu->gpu_uuid = (gpu_uuid != NULL) ? 1 : 0;
376
390
    ctk_gpu->memory_interface = (memory_interface != NULL) ? 1 : 0;
377
391
    ctk_gpu->ctk_config = ctk_config;
378
392
    ctk_gpu->ctk_event = ctk_event;
403
417
    /*
404
418
     * GPU information: TOP->MIDDLE - LEFT->RIGHT
405
419
     *
406
 
     * This displays basic display adatper information, including
 
420
     * This displays basic display adapter information, including
407
421
     * product name, bios version, bus type, video ram and interrupt
408
422
     * line.
409
423
     */
429
443
    add_table_row(table, row++,
430
444
                  0, 0.5, "Graphics Processor:",
431
445
                  0, 0.5, product_name);
 
446
    if ( ctk_gpu->gpu_uuid ) {
 
447
        add_table_row(table, row++,
 
448
                      0, 0.5, "GPU UUID:",
 
449
                      0, 0.5, gpu_uuid);
 
450
    }
432
451
    if ( ctk_gpu->gpu_cores ) {
433
452
        gtk_table_resize(GTK_TABLE(table), ++total_rows, 2);
434
453
        add_table_row(table, row++,
435
454
                      0, 0.5, "CUDA Cores:",
436
455
                      0, 0.5, gpu_cores);
437
456
    }
438
 
    add_table_row(table, row++,
439
 
                  0, 0.5, "VBIOS Version:",
440
 
                  0, 0.5, vbios_version);
 
457
    if ( vbios_version ) {
 
458
        add_table_row(table, row++,
 
459
                      0, 0.5, "VBIOS Version:",
 
460
                      0, 0.5, vbios_version);
 
461
    }
441
462
    add_table_row(table, row++,
442
463
                  0, 0.5, "Total Memory:",
443
464
                  0, 0.5, video_ram);
448
469
        add_table_row(table, row++,
449
470
                      0, 0.5, "Used Dedicated Memory:",
450
471
                      0, 0.5, NULL);
451
 
    update_gpu_memory_used(ctk_gpu);
452
472
    if ( ctk_gpu->memory_interface ) {
453
473
        gtk_table_resize(GTK_TABLE(table), ++total_rows, 2);
454
474
        add_table_row(table, row++,
455
475
                      0, 0.5, "Memory Interface:",
456
476
                      0, 0.5, memory_interface);
457
477
    }
 
478
    ctk_gpu->gpu_utilization_label =
 
479
        add_table_row(table, row++,
 
480
                      0, 0.5, "GPU Utilization:",
 
481
                      0, 0.5, NULL);
 
482
    ctk_gpu->video_utilization_label =
 
483
        add_table_row(table, row++,
 
484
                      0, 0.5, "Video Engine Utilization:",
 
485
                      0, 0.5, NULL);
458
486
    /* spacing */
459
487
    row += 3;
460
488
    add_table_row(table, row++,
461
489
                  0, 0.5, "Bus Type:",
462
490
                  0, 0.5, bus);
463
 
    add_table_row(table, row++,
464
 
                  0, 0.5, "Bus ID:",
465
 
                  0, 0.5, pci_bus_id);
466
 
    add_table_row(table, row++,
467
 
                  0, 0.5, "PCI Device ID:",
468
 
                  0, 0.5, pci_device_id);
469
 
    add_table_row(table, row++,
470
 
                  0, 0.5, "PCI Vendor ID:",
471
 
                  0, 0.5, pci_vendor_id);
472
 
    add_table_row(table, row++,
473
 
                  0, 0.5, "IRQ:",
474
 
                  0, 0.5, irq);
 
491
    if ( pci_bus_id ) {
 
492
        add_table_row(table, row++,
 
493
                      0, 0.5, "Bus ID:",
 
494
                      0, 0.5, pci_bus_id);
 
495
    }
 
496
    if ( pci_device_id[0] ) {
 
497
        add_table_row(table, row++,
 
498
                      0, 0.5, "PCI Device ID:",
 
499
                      0, 0.5, pci_device_id);
 
500
    }
 
501
    if (pci_vendor_id[0] ) {
 
502
        add_table_row(table, row++,
 
503
                      0, 0.5, "PCI Vendor ID:",
 
504
                      0, 0.5, pci_vendor_id);
 
505
    }
 
506
    if ( irq ) {
 
507
        add_table_row(table, row++,
 
508
                      0, 0.5, "IRQ:",
 
509
                      0, 0.5, irq);
 
510
    }
475
511
    if (ctk_gpu->pcie_gen_queriable) { 
476
512
        /* spacing */
477
513
        row += 3;
484
520
        add_table_row(table, row++,
485
521
                      0, 0.5, "Maximum PCIe Link Speed:",
486
522
                      0, 0.5, link_speed_str);
 
523
        ctk_gpu->pcie_utilization_label =
 
524
            add_table_row(table, row++,
 
525
                          0, 0.5, "PCIe Bandwidth Utilization:",
 
526
                          0, 0.5, NULL);
 
527
 
487
528
        g_free(link_speed_str);
488
529
        g_free(link_width_str);
489
530
        g_free(pcie_gen_str);
490
531
        row++;
491
532
    }
492
533
 
 
534
    update_gpu_usage(ctk_gpu);
493
535
    /* spacing */
494
536
    row += 3;
495
537
    add_table_row(table, row++,
531
573
    ctk_config_add_timer(ctk_gpu->ctk_config,
532
574
                         DEFAULT_UPDATE_GPU_INFO_TIME_INTERVAL,
533
575
                         tmp_str,
534
 
                         (GSourceFunc) update_gpu_memory_used,
 
576
                         (GSourceFunc) update_gpu_usage,
535
577
                         (gpointer) ctk_gpu);
536
578
    g_free(tmp_str);
537
579
 
559
601
    ctk_help_heading(b, &i, "Graphics Processor");
560
602
    ctk_help_para(b, &i, "This is the product name of the GPU.");
561
603
    
 
604
    if (ctk_gpu->gpu_uuid) {
 
605
        ctk_help_heading(b, &i, "GPU UUID");
 
606
        ctk_help_para(b, &i, "This is the global unique identifier "
 
607
                      "of the GPU.");
 
608
    }
 
609
    
562
610
    if (ctk_gpu->gpu_cores) {
563
611
        ctk_help_heading(b, &i, "CUDA Cores");
564
612
        ctk_help_para(b, &i, "This is the number of CUDA cores supported by "
591
639
                      "memory interface.");
592
640
    }
593
641
 
 
642
    ctk_help_heading(b, &i, "GPU Utilization");
 
643
    ctk_help_para(b, &i, "This is the percentage usage of graphics engine.");
 
644
 
 
645
    ctk_help_heading(b, &i, "Video Engine Utilization");
 
646
    ctk_help_para(b, &i, "This is the percentage usage of video engine");
 
647
 
594
648
    ctk_help_heading(b, &i, "Bus Type");
595
649
    ctk_help_para(b, &i, "This is the bus type which is "
596
650
                  "used to connect the NVIDIA GPU to the rest of "
602
656
                  "in X configuration file 'BusID' format: "
603
657
                  "\"bus:device:function\", or, if the PCI domain of the GPU "
604
658
                  "is non-zero, \"bus@domain:device:function\".  Note "
605
 
                  "that all values are in decimal (as opposed to hexidecimal, "
 
659
                  "that all values are in decimal (as opposed to hexadecimal, "
606
660
                  "which is how `lspci` formats its BusID values).");
607
661
 
608
662
    ctk_help_heading(b, &i, "PCI Device ID");
634
688
                      "This is expressed in gigatransfers per second "
635
689
                      "(GT/s).  The link may be dynamically trained to a "
636
690
                      "slower speed, based on the GPU's utilization and "
637
 
                      "performance settings."); 
 
691
                      "performance settings.");
 
692
 
 
693
        ctk_help_heading(b, &i, "PCIe Bandwidth Utilization");
 
694
        ctk_help_para(b, &i, "This is the percentage usage of "
 
695
                      "PCIe bandwidth.");
 
696
 
638
697
    }
639
698
    
640
699
    ctk_help_heading(b, &i, "X Screens");
664
723
    g_free(str);
665
724
}
666
725
 
667
 
static gboolean update_gpu_memory_used(gpointer user_data)
 
726
 
 
727
 
 
728
static void apply_gpu_utilization_token(char *token, char *value, void *data)
 
729
{
 
730
    utilizationEntryPtr pEntry = (utilizationEntryPtr) data;
 
731
 
 
732
    if (!strcasecmp("graphics", token)) {
 
733
        pEntry->graphics = atoi(value);
 
734
    } else if (!strcasecmp("video", token)) {
 
735
        pEntry->video = atoi(value);
 
736
    } else if (!strcasecmp("pcie", token)) {
 
737
        pEntry->pcie = atoi(value);
 
738
    } else {
 
739
        nv_warning_msg("Unknown GPU utilization token value pair: %s=%s",
 
740
                       token, value);
 
741
    }
 
742
}
 
743
 
 
744
 
 
745
 
 
746
static gboolean update_gpu_usage(gpointer user_data)
668
747
{
669
748
    CtkGpu *ctk_gpu;
670
749
    gchar *memory_text;
 
750
    gchar *utilization_text = NULL;
671
751
    ReturnStatus ret;
672
 
    int value;
673
 
    static int num_failures = 0;
 
752
    gchar *utilizationStr = NULL;
 
753
    gint value = 0;
 
754
    utilizationEntry entry;
674
755
 
675
756
    ctk_gpu = CTK_GPU(user_data);
676
757
 
679
760
                             &value);
680
761
    if (ret != NvCtrlSuccess || value > ctk_gpu->gpu_memory || value < 0) {
681
762
        gtk_label_set_text(GTK_LABEL(ctk_gpu->gpu_memory_used_label), "Unknown");
682
 
        if(num_failures++ >= 10) {
683
 
            return FALSE;
684
 
        }
 
763
        return FALSE;
685
764
    } else {
686
765
        if (ctk_gpu->gpu_memory > 0) {
687
766
            memory_text = g_strdup_printf("%d MB (%.0f%%)", 
696
775
        g_free(memory_text);
697
776
    }
698
777
 
 
778
    /* GPU utilization */
 
779
    ret = NvCtrlGetStringAttribute(ctk_gpu->handle,
 
780
                                   NV_CTRL_STRING_GPU_UTILIZATION,
 
781
                                   &utilizationStr);
 
782
    if (ret != NvCtrlSuccess) {
 
783
        gtk_label_set_text(GTK_LABEL(ctk_gpu->gpu_utilization_label), "Unknown");
 
784
        gtk_label_set_text(GTK_LABEL(ctk_gpu->video_utilization_label),
 
785
                           "Unknown");
 
786
        if (ctk_gpu->pcie_utilization_label) {
 
787
            gtk_label_set_text(GTK_LABEL(ctk_gpu->pcie_utilization_label),
 
788
                               "Unknown");
 
789
        }
 
790
        return FALSE;
 
791
    } else {
 
792
        memset(&entry, -1, sizeof(&entry));
 
793
        parse_token_value_pairs(utilizationStr, apply_gpu_utilization_token,
 
794
                                &entry);
 
795
        if (entry.graphics != -1) {
 
796
            utilization_text = g_strdup_printf("%d %%",
 
797
                                               entry.graphics);                                     
 
798
 
 
799
            gtk_label_set_text(GTK_LABEL(ctk_gpu->gpu_utilization_label),
 
800
                               utilization_text);
 
801
        }
 
802
        if (entry.video != -1) {
 
803
            utilization_text = g_strdup_printf("%d %%",
 
804
                                               entry.video);
 
805
 
 
806
            gtk_label_set_text(GTK_LABEL(ctk_gpu->video_utilization_label),
 
807
                               utilization_text);
 
808
        }
 
809
        if ((entry.pcie != -1) &&
 
810
            (ctk_gpu->pcie_utilization_label)) {
 
811
            utilization_text = g_strdup_printf("%d %%",
 
812
                                               entry.pcie);
 
813
 
 
814
            gtk_label_set_text(GTK_LABEL(ctk_gpu->pcie_utilization_label),
 
815
                               utilization_text);
 
816
        }
 
817
        g_free(utilization_text);
 
818
    }
699
819
    return TRUE;
700
820
}
701
821
 
703
823
{
704
824
    CtkGpu *ctk_gpu = CTK_GPU(widget);
705
825
 
 
826
    /* Update GPU usage */
 
827
 
 
828
    update_gpu_usage(ctk_gpu);
 
829
 
706
830
    /* Start the gpu timer */
707
831
 
708
832
    ctk_config_start_timer(ctk_gpu->ctk_config,
709
 
                           (GSourceFunc) update_gpu_memory_used,
 
833
                           (GSourceFunc) update_gpu_usage,
710
834
                           (gpointer) ctk_gpu);
711
835
}
712
836
 
717
841
    /* Stop the gpu timer */
718
842
 
719
843
    ctk_config_stop_timer(ctk_gpu->ctk_config,
720
 
                          (GSourceFunc) update_gpu_memory_used,
 
844
                          (GSourceFunc) update_gpu_usage,
721
845
                          (gpointer) ctk_gpu);
722
846
}
723
847