summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/memcpy_avx512.h
AgeCommit message (Expand)AuthorFilesLines
2021-02-15vppinfra: fix memcpy undefined behaviourBenoît Ganne1-1/+1
2020-04-27vppinfra: selectively disable false-positive GCC-10 warningsBenoît Ganne1-0/+8
2018-11-14Remove c-11 memcpy checks from perf-critical codeDave Barach1-1/+1
2018-10-23c11 safe string handling supportDave Barach1-1/+1
2018-09-27Trivial: Cleanup some typos.Paul Vinciguerra1-1/+1
2017-12-14vppinfra: add AVX512 variant of clib_memcpyDamjan Marion1-0/+277
a id='n145' href='#n145'>145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
/*
 *------------------------------------------------------------------
 * Copyright (c) 2006-2016 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <gtk/gtk.h>
#define GTK_ENABLE_BROKEN // DGMS
#include <gtk/gtktext.h>
#include <stdlib.h>
#include "g2.h"
#include <string.h>

/*
 * locals
 */
static GtkWidget *s_mainmenubar;
static GtkWidget *s_filemenu;
static GtkWidget *s_readdefs;
static GtkWidget *s_readevents;
static GtkWidget *s_readeventsclock;
static GtkWidget *s_readcpel;
static GtkWidget *s_readclib;
static GtkWidget *s_print;
static GtkWidget *s_quit;

static GtkWidget *s_mainfilemenu;
static GtkWidget *s_help_general;
static GtkWidget *s_help_about;
static GtkWidget *s_mainhelpmenu;
static GtkWidget *s_helpmenu;

static GtkWidget *s_filesel;
static GtkWidget *s_eventsel;

typedef struct md_ {
    GtkWidget *entry;
    GtkWidget *label;
    GtkWidget *dialog;
    boolean (*callback)(char *);
    char *retry_text;
} md_t;

char *general_help = "\n"
"G2 is a performance event visualization tool.\n"
"\n"
"To view CPEL-format event data:\n"
"g2 --cpel <filename>\n"
"or use the File Menu->Read CPEL file option.\n"
"\n"
"To view vppinfra-format (.../open-repo/vppinfra/vppinfra/elog.h) event data:\n"
"g2 --clib <filename>\n"
"or use the File Menu->Read clib file option.\n"
"\n"
"To toggle event detail boxes, left-mouse-click on an event.\n"
"\n"
"To zoom to an area, depress the left mouse button. Move the\n"
"mouse. Release the mouse.\n"
"\n"
"To use the time ruler, depress the right mouse button.  Move the\n"
"mouse. Release when done.\n"
"\n"
"To push a track to the bottom, <ctrl><left-mouse>\n"
"\n"
"To pull a track to the top, <shift><left-mouse>\n"
"\n"
"To selectively color/uncolor a track, <ctrl><shift><left-mouse>\n"
"\n"
"To make the mouse scrollwheel faster, press <shift>\n"
"\n"
"Hotkeys, supposedly Quake-like:\n"
"      w - zoom-in\n"
"      s - zoom-out\n"
"      a - pan-left\n"
"      d - pan-right\n"
"      r - pan-up\n"
"      f - pan-down\n"
"      t - less traces\n"
"      g - more traces\n"
"\n"
"      e - toggle summary-mode\n"
"      c - toggle color-mode\n"
"\n"
"      x - take snapshot\n"
"      z - go to next snapshot\n"
"      p - put snapshots to snapshots.g2 \n"
"      l - load snapshots from snapshots.g2\n"
"\n"
"<ctrl>q - quit\n"
"Send comments / bug reports to the \"fd.io\" mailing list.\n";

/****************************************************************************
* debug_dialog_callback
****************************************************************************/

boolean debug_dialog_callback (char *s)
{
    g_print("Dialog result: %s", s);
    return (TRUE);
}

/****************************************************************************
* get_dialog_value
****************************************************************************/

static void get_dialog_value (GtkWidget *dialog, gpointer user_data)
{
    md_t *md = (md_t *)user_data;
    char * cb_arg;

    cb_arg = (char *) gtk_entry_get_text(GTK_ENTRY(md->entry));

    if ((*md->callback)(cb_arg)) {
	gtk_grab_remove(md->dialog);
	gtk_widget_destroy(md->dialog);
    } else {
	gtk_label_set_text (GTK_LABEL(md->label), md->retry_text);
    }
}

/****************************************************************************
* modal_dialog
****************************************************************************/

void modal_dialog (char *label_text, char *retry_text, char *default_value,
                   boolean (*cb)(char *))
{
    GtkWidget *dialog, *label, *ok_button, *entry;
    static md_t dlg;
    md_t *md = &dlg;

    dialog = gtk_dialog_new();
    label = gtk_label_new(label_text);

    entry = gtk_entry_new();
    if (default_value)
        gtk_entry_set_text(GTK_ENTRY(entry), default_value);

    ok_button = gtk_button_new_with_label("OK");

    md->entry = entry;
    md->label = label;
    md->retry_text = retry_text;
    md->dialog = dialog;
    if (cb)
	md->callback = cb;
    else
	md->callback = debug_dialog_callback;

    gtk_signal_connect (GTK_OBJECT (ok_button), "clicked",
                        GTK_SIGNAL_FUNC(get_dialog_value), (gpointer) md);

    gtk_signal_connect (GTK_OBJECT (entry), "activate",
                        GTK_SIGNAL_FUNC(get_dialog_value), (gpointer) md);

    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
		      entry);

    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
		      ok_button);
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
    gtk_widget_show_all(dialog);
    gtk_widget_grab_focus(entry);
    gtk_grab_add(dialog);
}

/****************************************************************************
* get_eventdef_name
****************************************************************************/

static void get_eventdef_name (GtkFileSelection *sel, gpointer user_data)
{
    char *filename = (char *) gtk_file_selection_get_filename (
        GTK_FILE_SELECTION(s_filesel));
    read_event_definitions(filename);
    set_window_title(filename);
}

/****************************************************************************
* read_eventdef_callback
****************************************************************************/

static void read_eventdef_callback(GtkToggleButton *item, gpointer data)
{

    s_filesel = gtk_file_selection_new("Read Event Definitions From...");

    gtk_file_selection_set_filename(GTK_FILE_SELECTION(s_filesel),
				    "../h/elog.h");

    gtk_signal_connect (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->ok_button),
                        "clicked",
                        GTK_SIGNAL_FUNC(get_eventdef_name), NULL);

    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->ok_button),
                               "clicked",
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_filesel);

    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->cancel_button),
                               "clicked",
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_filesel);
    gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(s_filesel));
    gtk_widget_show (s_filesel);
}

/****************************************************************************
* get_events_name
****************************************************************************/

static void get_events_name (GtkFileSelection *sel, gpointer user_data)
{
    char *filename = (char *) gtk_file_selection_get_filename (
        GTK_FILE_SELECTION(s_eventsel));
    read_events(filename);
    view1_display_when_idle();
}


/****************************************************************************
* get_ticks_per_ns
****************************************************************************/

static boolean get_ticks_per_ns (char *value)
{
    double rv;

    rv = atof (value);

    if (rv == 0.0 || rv > 100000)
	return(FALSE);

    ticks_per_ns = rv;
    ticks_per_ns_set = TRUE;

    gtk_widget_show(s_eventsel);
    return(TRUE);
}

/****************************************************************************
* read_events_callback
****************************************************************************/

static void read_events_callback(GtkToggleButton *item, gpointer data)
{
    char tmpbuf [32];

    s_eventsel = gtk_file_selection_new("Read Events From...");

    gtk_signal_connect (GTK_OBJECT (
        GTK_FILE_SELECTION(s_eventsel)->ok_button),
                        "clicked",
                        GTK_SIGNAL_FUNC(get_events_name), NULL);

    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_eventsel)->ok_button),
                               "clicked",
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_eventsel);

    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_eventsel)->cancel_button),
                               "clicked",
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_eventsel);
    gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(s_eventsel));

    if (ticks_per_ns_set)
	gtk_widget_show (s_eventsel);
    else {
	snprintf(tmpbuf, sizeof(tmpbuf), "%.3f", ticks_per_ns);
	modal_dialog ("Please enter clock ticks per nanosecond",
		      "Invalid: Please enter clock ticks per nanosecond",
		      tmpbuf, get_ticks_per_ns);
    }
}

/****************************************************************************
* read_eventclock_callback
****************************************************************************/

static void read_eventsclock_callback(GtkToggleButton *item, gpointer data)
{
    ticks_per_ns_set = FALSE;
    read_events_callback(item, data);
}

/****************************************************************************
* infobox_size_request
****************************************************************************/

void infobox_size_request (GtkWidget *widget, GtkRequisition *req,
                           gpointer user_data)
{
    char *text = (char *)user_data;
    char *cp;
    int widest_line_in_chars;
    int w;
    int nlines;

    /*
     * You'd think that the string extent function would work here.
     * You'd be wrong.
     */
    nlines = w = widest_line_in_chars = 0;
    for (cp = text; *cp; cp++) {
        if (*cp == '\n') {
            if (w > widest_line_in_chars) {
                widest_line_in_chars = w;
            }
            w = 0;
            nlines++;
        }
        w++;
    }

    nlines++;

    req->width = (widest_line_in_chars * 8) + 20;
    req->height = (nlines * 13) + 10;
}

/****************************************************************************
* infobox
****************************************************************************/

void infobox(char *label_text, char *text)
{
    GtkWidget *dialog, *label, *ok_button, *entry;
    GtkWidget *box;

    dialog = gtk_dialog_new();
    label = gtk_label_new(label_text);

    entry = gtk_text_new(NULL, NULL);

    gtk_signal_connect (GTK_OBJECT (entry), "size-request",
                        GTK_SIGNAL_FUNC(infobox_size_request),
                        (gpointer) text);

    gtk_text_insert(GTK_TEXT(entry), g_font, &fg_black, &bg_white,
                    text, -1);

    gtk_text_set_editable(GTK_TEXT(entry), FALSE);

    ok_button = gtk_button_new_with_label("OK");

    gtk_signal_connect_object (GTK_OBJECT (ok_button), "clicked",
                               GTK_SIGNAL_FUNC(gtk_widget_destroy),
                               (gpointer) GTK_OBJECT(dialog));

    box = gtk_vbox_new(FALSE, 5);


    gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0);
    gtk_box_pack_start(GTK_BOX(box), ok_button, FALSE, FALSE, 0);

    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
		      box);

    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
    gtk_widget_show_all(dialog);
}

/****************************************************************************
* help_general_callback
****************************************************************************/

static void help_general_callback(GtkToggleButton *item, gpointer data)
{
    infobox("General Help", general_help);
}

/****************************************************************************
* help_about_callback
****************************************************************************/

static void help_about_callback(GtkToggleButton *item, gpointer data)
{
    char tmpbuf [1024];
    snprintf (tmpbuf, sizeof(tmpbuf), "G2 -- Graphical Event Viewer\n\n");
    view1_about(tmpbuf);
    pointsel_about(tmpbuf);
    events_about(tmpbuf);
    snprintf (tmpbuf+strlen(tmpbuf), sizeof(tmpbuf) - strlen(tmpbuf),
             "\n%s\n", version_string);
    snprintf (tmpbuf+strlen(tmpbuf), sizeof(tmpbuf) - strlen(tmpbuf),
             "%s\n", minor_v_string);
    infobox("About", tmpbuf);
}


/****************************************************************************
* get_cpel_name
****************************************************************************/

static void get_cpel_name (GtkFileSelection *sel, gpointer user_data)
{
    char *filename = (char *)gtk_file_selection_get_filename (
        GTK_FILE_SELECTION(s_filesel));
    read_cpel_file(filename);
    set_window_title(filename);
}

/****************************************************************************
* get_clib_name
****************************************************************************/

static void get_clib_name (GtkFileSelection *sel, gpointer user_data)
{
    char *filename = (char *) gtk_file_selection_get_filename (
        GTK_FILE_SELECTION(s_filesel));
    read_clib_file(filename);
    set_window_title(filename);
}

/****************************************************************************
* read_cpel_callback
****************************************************************************/

static void read_cpel_callback(GtkToggleButton *item, gpointer data)
{

    s_filesel = gtk_file_selection_new("Read CPEL data from...");

    gtk_file_selection_set_filename(GTK_FILE_SELECTION(s_filesel),
				    "cpel.out");

    gtk_signal_connect (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->ok_button),
                        "clicked",
                        GTK_SIGNAL_FUNC(get_cpel_name), NULL);

    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->ok_button),
                               "clicked",
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_filesel);

    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->cancel_button),
                               "clicked",
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_filesel);
    gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(s_filesel));
    gtk_widget_show (s_filesel);
}

/****************************************************************************
* read_clib_callback
****************************************************************************/

static void read_clib_callback(GtkToggleButton *item, gpointer data)
{

    s_filesel = gtk_file_selection_new("Read clib data From...");

    gtk_file_selection_set_filename(GTK_FILE_SELECTION(s_filesel),
				    "clib.out");

    gtk_signal_connect (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->ok_button),
                        "clicked",
                        GTK_SIGNAL_FUNC(get_clib_name), NULL);

    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->ok_button),
                               "clicked",
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_filesel);

    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->cancel_button),
                               "clicked",
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_filesel);
    gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(s_filesel));
    gtk_widget_show (s_filesel);
}

/****************************************************************************
* menu1_init
****************************************************************************/

void menu1_init(void)
{

    s_filemenu = gtk_menu_new();

    s_readcpel = gtk_menu_item_new_with_label
	("Read CPEL file");
    gtk_menu_append(GTK_MENU(s_filemenu), s_readcpel);
    gtk_signal_connect(GTK_OBJECT(s_readcpel), "activate",
                       GTK_SIGNAL_FUNC(read_cpel_callback), 0);

    s_readclib = gtk_menu_item_new_with_label
	("Read CLIB file");
    gtk_menu_append(GTK_MENU(s_filemenu), s_readclib);
    gtk_signal_connect(GTK_OBJECT(s_readclib), "activate",
                       GTK_SIGNAL_FUNC(read_clib_callback), 0);

    s_readdefs = gtk_menu_item_new_with_label ("Read Event Definitions");
    gtk_menu_append(GTK_MENU(s_filemenu), s_readdefs);
    gtk_signal_connect(GTK_OBJECT(s_readdefs), "activate",
                       GTK_SIGNAL_FUNC(read_eventdef_callback), 0);

    s_readevents = gtk_menu_item_new_with_label ("Read Event Log");
    gtk_menu_append(GTK_MENU(s_filemenu), s_readevents);
    gtk_signal_connect(GTK_OBJECT(s_readevents), "activate",
                       GTK_SIGNAL_FUNC(read_events_callback), 0);

    s_readeventsclock = gtk_menu_item_new_with_label
	("Read Event Log with Different Clock Rate");
    gtk_menu_append(GTK_MENU(s_filemenu), s_readeventsclock);
    gtk_signal_connect(GTK_OBJECT(s_readeventsclock), "activate",
                       GTK_SIGNAL_FUNC(read_eventsclock_callback), 0);

    s_print = gtk_menu_item_new_with_label ("Print");
    gtk_menu_append(GTK_MENU(s_filemenu), s_print);
    gtk_signal_connect(GTK_OBJECT(s_print), "activate",
                       GTK_SIGNAL_FUNC(view1_print_callback), 0);

    s_quit = gtk_menu_item_new_with_label ("Exit");
    gtk_menu_append(GTK_MENU(s_filemenu), s_quit);
    gtk_signal_connect(GTK_OBJECT(s_quit), "activate",
                       GTK_SIGNAL_FUNC(gtk_main_quit), 0);

    s_mainfilemenu = gtk_menu_item_new_with_label("File");
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(s_mainfilemenu), s_filemenu);

    s_helpmenu = gtk_menu_new();

    s_help_general = gtk_menu_item_new_with_label ("General");
    gtk_menu_append(GTK_MENU(s_helpmenu), s_help_general);
    gtk_signal_connect(GTK_OBJECT(s_help_general), "activate",
                       GTK_SIGNAL_FUNC(help_general_callback), 0);

    s_help_about = gtk_menu_item_new_with_label ("About");
    gtk_menu_append(GTK_MENU(s_helpmenu), s_help_about);
    gtk_signal_connect(GTK_OBJECT(s_help_about), "activate",
                       GTK_SIGNAL_FUNC(help_about_callback), 0);

    s_mainhelpmenu = gtk_menu_item_new_with_label("Help");
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(s_mainhelpmenu), s_helpmenu);

    s_mainmenubar = gtk_menu_bar_new();
    gtk_menu_bar_append(GTK_MENU_BAR(s_mainmenubar), s_mainfilemenu);
    gtk_menu_bar_append(GTK_MENU_BAR(s_mainmenubar), s_mainhelpmenu);
    gtk_widget_show_all(s_mainmenubar);

    gtk_box_pack_start(GTK_BOX(g_mainvbox), s_mainmenubar, FALSE, FALSE, 0);
}