Está en la página 1de 30

Programacin en los

procecesadores Intel Multi


Core

Qu son las instrucciones mquina?


Conjunto de instrucciones
La coleccin de instrucciones que entiende un CPU
Lenguaje mquina
Usualmente representado por cdigos en ensamblador
Se almacena en binario

2
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Elementos de una instruccin


Cdigo de operacin (Op code)
Hacer esto
Referencia al operando fuente
A esto
Referencia al operando resultante
Poner la respuesta aqu

MOV 5 , EAX

3
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Ejecucin de instrucciones
Secuencial
Pipelinening
Superescalar
Paralelo

4
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Ejecucuin de una secuencia de


instrucciones
Flujo de instrucciones

ADD EBX, EAX (EAX := EAX+EBX;)


MOV EAX, ECX (ECX := EAX;)

EAX=1
EAX=3
EBX=2
ECX=3
CPU 1

5
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Ejecucin de instrucciones (secuencial)

Captacin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin

1
2
3
4
5
6
7
8

Decodificacin
Calcula operandos
Capta operandos
Ejecuta instruccin
Escribe operandos

6
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Ejecucin de instrucciones (pipelinening)

Captacin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin

1
2
3
4
5
6
7
8

Decodificacin
Calcula operandos
Capta operandos
Ejecuta instruccin
Escribe operandos

7
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Plataformas para computacin en paralelo


Diferentes arquitecturas
SMP
Hyper threading
Multi core

8
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Multi Core Vs Hyper Threading

Estado del CPU


Lgica de Interrupciones
Unidades de
Ejecucin

Cache

Single Core

Estado del CPU

Estado del CPU

Lgica de Interrupciones

Lgica de Interrupciones

Unidades de
Ejecucin

Cache

Unidades de
Ejecucin

Cache

Multiprocesador (SMP)
9
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Multi Core Vs Hyper Threading

Estado del CPU

Estado del CPU

Lgica de Interrupciones

Lgica de Interrupciones

Unidades de
Ejecucin

Cache

Tecnologa Hyper Threading

Estado del CPU

Estado del CPU

Lgica de Interrupciones

Lgica de Interrupciones

Unidades de
Ejecucin

Cache

Unidades de
Ejecucin

Cache

Multi Core
10
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Multi Core Vs Hyper Threading

Estado del CPU

Estado del CPU

Lgica de Interrupciones

Lgica de Interrupciones

Unidades de
Ejecucin

Unidades de
Ejecucin

Cache

Multi Core con cach compartida

Estado del CPU

Estado del CPU

Estado del CPU

Estado del CPU

Lgica de Interrupciones

Lgica de Interrupciones

Lgica de Interrupciones

Lgica de Interrupciones

Unidades de
Ejecucin

Cache

Unidades de
Ejecucin

Cache

Multi Core con tecnologa Hyper Threading


11
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Para que sirve tener dos o ms ncleo en


un CPU?
Puedo ejecutar en paralelo instrucciones de una secuencia?

Dependencias

12
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Dependencias
Flujo de instrucciones

ADD EBX, EAX (EAX := EAX+EBX;)


MOV EAX, ECX (ECX := EAX;)

EAX=1

EAX=1
EAX=3

EBX=2

EBX=2

ECX=3
ECX=1

ECX=3

CPU 1

CPU 2

Puede extraer y decodificar la segunda instruccin en paralelo con la


primera
No puede ejecutar la segunda instruccin hasta que la primera haya
finalizado
13
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Para que sirve tener dos o ms ncleo en


un CPU?
Aumentar tasa de trabajos
Qu tipo de trabajos?
Trabajos que hacen uso intensivo del CPU
Trabajos que requieren E/S
Trabajos mixtos

14
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Trabajos que hacen uso intensivo del CPU


Un trabajo en un nucleo
10 segundos
Tiempo de
retorno =10
segs
En el CPU

1 trabajo en 10 segundos
Tasa = 1 / 10 = 0.1
15
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Trabajos que hacen uso intensivo del CPU


Dos trabajos en un nucleo
10 segundos
10 segundos

En el CPU

Tiempo de retorno P0 =20


segs
Tiempo de retorno P1 =20
segs

2 trabajos en 20 segundos
Tasa = 2 / 20 = 0.1
16
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Trabajos que hacen uso intensivo del CPU


Con un CPU
El tiempo de retorno aumenta
La tasa de trabajos se mantiene

17
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Trabajos que hacen uso intensivo del CPU


El tiempo de retorno de
los procesos puede
variar
Prioridades
Politicas de
platinificacin

Dos trabajos en un nucleo


10 segundos
10 segundos
En el CPU

Tiempo de retorno
Tiempo de retorno
P0 =15 segs
P1=19 segs

2 trabajos en 20 segundosLa tasa de trabajos


Tasa = 2 / 20 = 0.1

se mantiene igual

18
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Trabajos que hacen uso intensivo del CPU


Un trabajo en dos nucleos
10 segundos
Tiempo de
retorno =10
segs

No hay mejora en
el tiempo de
retorno ni la tasa
de trabajos

Nucleo 0
Nucleo 1

1 trabajo en 10 segundos
Tasa = 1 / 10 = 0.1
19
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Trabajos que hacen uso intensivo del CPU


Dos trabajos en dos ncleos
10 segundos
10 segundos

El tiempo de retorno
se mantiene igual
que cuando
ejecutamos un
trabajo

Tiempo de
retorno =10
segs

Nucleo 0
Nucleo 1

La tasa de
trabajos aumenta
al doble

2 trabajos en 10 segundos
Tasa = 2 / 10 = 0.2

20
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Multi core
Encontramos mejora en la tasa de trabajos y tiempo de retorno
cuando ejecutamos dos procesos concurrentes.
Hasta ahora un solo proceso no es capaz de obtener beneficio
de las arquitecturas MultiCore

21
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Trabajos que hacen uso intensivo del CPU


Un trabajo optimizado en dos nucleos
5 segundos
5 segundos
10 segundos
Hilo 0

Hilo 1

Tiempo de
retorno =5 segs

Nucleo 0
Nucleo 1

1 trabajo en 5 segundos
Tasa = 1 / 5 = 0.2
22
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Definiendo los Hilos


Un hilo es una secuencia de instrucciones relacionadas que se
ejecuta de forma independiente a otras secuencias

Todos los programas tienen al menos un hilo principal


Inicializa el programa y comienza la ejecucin de las
instrucciones iniciales
Puede crear otros hilos que ejecuten varias tareas o puede
hacer todo el trabajo el solo

23
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Dividiendo una aplicacin en hilos


Un proceso puede dividirse en mltiples hilos
Mejor uso de los recursos de hardware
Es necesario entender
Diseo y estructura de la aplicacin
La interfase de programacin con hilos
El compilador y el ambiente de ejecucin de la aplicacin
Las plataformas destino donde la aplicacin se va a ejecutar

24
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Hilos en plataformas single core

Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin

Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin

Estado del CPU


Lgica de Interrupciones
Cache

Single Core
Unidades de ejecucin

25
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Hilos en plataformas Hyper Threading


Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin

Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Tecnologa Hyper Threading

Estado del CPU

Estado del CPU

Lgica de Interrupciones

Lgica de Interrupciones

Ambas instrucciones
requieren una
diferentes
misma
unidades
unidad
funcional
funcionales

Cache
Unidades de ejecucin

26
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Multi-hilos en plataformas multi core


Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin

Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin
Instruccin

Estado del CPU

Estado del CPU

Lgica de Interrupciones

Lgica de Interrupciones

Cache

Multi Core
Unidades de ejecucin

Cache
Unidades de ejecucin

27
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Hilos en plataformas single core


Concurrencia
Dos o ms hilos se ejecutan en el mismo procesador
El tiempo del procesador se divide dando turnos a los dos
hilos de manera que pueden avanzar

28
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Hilos en plataformas multi core


Paralelismo
Dos o ms hilos se ejecutan simultneamente en dos o ms
procesadores
Cada hilo tiene el tiempo de un procesador

29
Copyright 2006, Intel Corporation. All rights reserved.
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.

Gracias!